Store Multiple Values in one Variable using JavaScript Arrays I'm stuck here

Modify the new array myArray so that it contains both a string and a number (in that order).

The example is: ````var sandwich = [“peanut butter”, “jelly”, “bread”]` .``` when i checked w3schools and the forum here: https://www.w3schools.com/js/js_arrays.asp it says the same

var cars = ["Saab", "Volvo", "BMW"];

but when i try:

var myArray = ["string", "number"];

it doesn’t work why? i also try replacing the word number with a 3 since it counts from 0

the error it gives me is: The second item in myArray should be a number. now i know that js reads from left to right so i change it

 var myArray = ["number", "string"];

keep having the error what am i doing wrong?

https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/store-multiple-values-in-one-variable-using-javascript-arrays

you are giving the word number as a string, it means to give an actual number without quotes, so like

let number = 23
let string = '23'

if you ever need to find out what type it is you can use typeof in the console.log

let number = '23'

console.log(typeof number) // returns string
1 Like

Thanks so much <3 I love you for this hahahaa

1 Like