JavaScript JavaScript Loops, Arrays and Objects Tracking Multiple Items with Arrays Create an Array

How to create an Array?

Create an array named data and store any 3 numbers in it.

I created an array and stored 3 numbers inside. I checked my work and got this message; Bummer! There was an error with your code. Syntax error; parse error.

What am I doing wrong?

script.js
var data = [
  '7' 
  '15' 
  '26'
];
index.html
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JavaScript Loops</title>
</head>
<body>
<script src="script.js"></script>
</body>
</html>

1 Answer

Jennifer Nordell
STAFF
Jennifer Nordell
Treehouse Staff

Close! Really close... but not quite. First, the elements in your array need to be separated by commas. But secondly and most importantly... those aren't numbers. I know... I know... they look like numbers, but because they are in quotes they're now strings. They are the kind of numbers we might use in a street address, telephone number, or social security number. It's nothing we would ever do any mathematical operations on. I've reformatted your array so it works. Take a look:

var data = [7, 15, 26];

Oops. I forgot, a string is enclosed in quotes, numbers aren't. I have the notes for numbers and strings, somewhere. I'll need to go back and look, to what makes a string and what makes a number.

Thank you so much for your help, Jennifer.

Victor Albarran
Victor Albarran
4,662 Points

I forgot too about that anything in quotes is a string and number do not need strings

thank you