Jump to content

jonnyenglish89

Members
  • Posts

    16
  • Joined

  • Last visited

jonnyenglish89's Achievements

Member

Member (2/5)

0

Reputation

  1. Great, I'll make the changes. thank you for the advice!
  2. Hi, I’d appreciate some help with my homework. I’ve got to display each student’s name and the results for each of their modules using vanilla JavaScript. the following code displays the values I’m after, but I’d really like to know how to improve it. var data = { "students":[ { "name":"Eric Smith", "modules":{ "1":{ "id":"COMP40003", "name":"Software Development", "result":80 }, "2":{ "id":"COMP40001", "name":"Digital technologies", "result":71 }, "3":{ "id":"COMP40004", "name":"Web Development", "result":47 }, "4":{ "id":"COMP40002", "name":"Networking Concepts and Cyber Security", "result":0 } } }, { "name":"Bob", "modules":{ "1":{ "id":"COMP40003", "name":"Software Development", "result":80 }, "2":{ "id":"COMP40001", "name":"Digital technologies", "result":71 }, "3":{ "id":"COMP40004", "name":"Web Development", "result":47 }, "4":{ "id":"COMP40002", "name":"Networking Concepts and Cyber Security", "result":0 } } } ] }; var json = JSON.parse(JSON.stringify(data)); for (var key in json["students"]) { console.log(json["students"][key]["name"]); console.log('-------------------'); for (var modkey in json["students"][key]["modules"]) { console.log(json["students"][key]["modules"][modkey]["name"] + " " + json["students"][key]["modules"][modkey]["result"]); console.log('-------------------'); }; }; Thanks
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.