The problem with the array code from the book "JavaScript for Dummies", what could be the problem?

  • 0
    The problem is that when writing this code AND it is that when trying to get a response in two different ways, it should return "PatsyCline: Sentimentally Yours" , but only return the letter of the element depending on the index of the element. Example in the second picture
    And if you do this through a web page, the situation is the same.
    Could this be because the code from the book was written in ES5?
    JavaScript Anonymous, Aug 23, 2019

  • 1 Answers
  • 0
    I can't even imagine what kind of book it is ...



    You create an array var bestAlbumsByGenre = []

    Next, you assign as the first element the LINE bestAlbumsByGenre [0] = "Country"

    And then you assign a new value to the line under the 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 Country string), and you assign another string instead - this is not customary for us, it does not work that way.



    If you go for this to work, then it must either be an object.

    var bestAlbumsByGenre  = {
    "Country": ["JohnyCash", "PatsyChine"],
    "Rock": []
    }




    or an array instead of a string

    bestAlbumsByGenre [0] = []

    bestAlbumsByGenre [0] [0] = "JohnyCash"
    Anonymous

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!