Solution 01
var aCar = {
owner : 'Joe Bloggs',
type : {
make : 'Toyota',
model : 'Corolla',
cc : 1.8
},
registration : '10WD1058'
}
console.log(aCar.owner + ' drives a ' + aCar.type.make)
Solution 02.
var aCar = {
owner : 'Joe Bloggs,
type : {
make : 'Toyota',
model : 'Corolla',
cc : 1.8
},
registration : {year : 10, county : 'WD', number : 1058}
}
console.log(aCar.owner + ' drives a ' + aCar.type.make)
console.log('Reg. = ' + aCar.registration.year + '-' +
aCar.registration.county + '-' +
aCar.registration.number )
Solution 03.
var aCar = {
owner : 'Joe Bloggs',
type : {
make : 'Toyota',
model : 'Corolla',
cc : 1.8
},
registration : {year : 10, county : 'WD', number : 1058}
}
console.log(aCar.owner + ' drives a ' + aCar.type.make)
console.log('Reg. = ' + aCar.registration.year + '-' +
aCar.registration.county + '-' +
aCar.registration.number )
aCar.mileage = 80000
aCar.color = { exterior : 'red',
interior : { texture : 'leather', shade : 'cream' }
}
console.log('It is a ' + aCar.color.exterior +
' car, ' + aCar.mileage + ' mileage, and ' +
aCar.color.interior.texture + ' interior.')
Solution 04.
var aCar = {
owner : 'Joe Bloggs',
previous_owners : [ { name : 'Pat Smith', address : '1 Main Street'},
{ name : 'Sheila Dwyer', address : '2 High Street'}],
. . . . . . . . .
registration : {year : 10, county : 'WD', number : 1058}
}
. . . . . . . .
console.log('First owner : ' + aCar.previous_owners[0].name +
' - ' + aCar.previous_owners[0].address )
Solution 05.
for (var i = 0 ; i < aCar.previous_owners.length ; i += 1) {
console.log(aCar.previous_owners[i].name)
}