Answer the question
In order to leave comments, you need to log in
Problem with array code from JavaScript for Dummies, what could be the problem?
The problem is that when writing this code, AND it is that when trying to get the answer in two different ways, it should return "PatsyCline:Sentimentally Yours" , but returns only the letter of the element, depending on the element index. Example in the second picture
And if you do it through a web page, the situation is the same.
Could this be due to the fact that the code in the book is written in ES5?
Answer the question
In order to leave comments, you need to log in
I can't even imagine what kind of book this is...
You create an array var bestAlbumsByGenre = []
Next, you assign the first element to a STRING bestAlbumsByGenre [0] = "Country"
And then you assign a new value to the string at index 0 bestAlbumsByGenre [0][0] = "JohnyCash"
The result of bestAlbumsByGenre[0][0] will be the letter C (the zero element of the zero element of the bestAlbumsByGenre array, that is, the first letter of the string Country), and you assign another string instead - this is not accepted with us, this does not work
If you go for it to work, then it must be either an object
var bestAlbumsByGenre = {
"Country": ["JohnyCash", "PatsyChine"],
"Rock": []
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question