Harjutus 2: JSON

Ülesanne: Loo Codesandbox-is HTML leht, mis kuvab auto andmeid

codesandbox.io – valime JavaScript, sisestame sinna järgmise koodi. Koodis on kirjeldatud massiiv, kus on olemas andmed ja nende väärtused.

import «./styles.css»; const myjson = [ { Car0: { Color: «Rose red», «Tinted windows»: false, Wheels: 4, «Roof cargo»: null, Audiosystem: «FM Radio, MP3, MP4 and MKV player, harman/kardon speakers», Accessories: «satnav, cruise control», }, Car1: { Color: «Navy blue», «Tinted windows»: true, Wheels: 4, «Roof cargo»: «thule», Audiosystem: «FM Radio, Apple CarPlay/Android Auto, Bowers & Wilkins Premium Sound speakers», Accessories: «self driven system, luggage cover», }, }, ]; document.getElementById(«app»).innerHTML = `

Car properties

Car 0

Color: ${myjson[0].Car0.Color}

Tinted windows: ${myjson[0].Car0[«Tinted windows»]}

Wheels: ${myjson[0].Car0[«Wheels»]}

Roof cargo: ${myjson[0].Car0[«Roof cargo»]}

Audiosystem: ${myjson[0].Car0[«Audiosystem»]}

Accessories: ${myjson[0].Car0[«Accessories»]}

Car 1

Color: ${myjson[0].Car1.Color}

Tinted windows: ${myjson[0].Car1[«Tinted windows»]}

Wheels: ${myjson[0].Car1[«Wheels»]}

Roof cargo: ${myjson[0].Car1[«Roof cargo»]}

Audiosystem: ${myjson[0].Car1[«Audiosystem»]}

Accessories: ${myjson[0].Car1[«Accessories»]}

`;