-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathocean.js
77 lines (60 loc) · 2.08 KB
/
ocean.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Title: Accesing Objects II
// Description: This is Level 4, Challenge 4
// Code solution by: Paola Garcia Cardenas
//Accesing Objects II
var vehicle1 = {type: "Motorboat", capacity: 6, storedAt: "Ammunition Depot"};
var vehicle2 = {type: "Jet Ski", capacity: 1, storedAt: "Reef Dock"};
var vehicle3 = {type: "Submarine", capacity: 8, storedAt: "Underwater Outpost"};
// create vehicles array
var vehicles = [vehicle1, vehicle2, vehicle3];
// build findVehicle function expression
var findVehicle = function(name, list) {
for (var i = 0; i < list.length; i++) {
if (list[i].type == name) {
return list[i].storedAt;
}
}
};
// call findVehicle
findVehicle("Submarine", vehicles);
var superBlinders = [
["Firelight", 4000],
["Solar Death Ray", 6000],
["Supernova", 12000]
];
var lighthouseRock = {
gateClosed: true,
bulbs: [200, 500, 750],
capacity: 30,
secretPassageTo: "Underwater Outpost"
};
// remove bulbs property from lighthouseRock
delete lighthouseRock.bulbs;
// add weaponBulbs property to lighthouseRock
lighthouseRock.weaponBulbs = superBlinders;
// log the correct weaponBulbs array value to the console
console.log(lighthouseRock.weaponBulbs[2][0]);
// Men Your Bulb Stations Part -->
var superBlinders = [ ["Firestorm", 4000], ["Solar Death Ray", 6000], ["Supernova", 12000] ];
var lighthouseRock = {
gateClosed: true,
weaponBulbs: superBlinders,
capacity: 30,
secretPassageTo: "Underwater Outpost",
numRangers: 3,
ranger1: {name: "Nick Walsh", skillz: "magnification burn", station: 2},
ranger2: {name: "Drew Barontini", skillz: "uppercut launch", station: 3},
ranger3: {name: "Christine Wong", skillz: "bomb defusing", station: 1}
};
function dontPanic(location) {
var list = "Avast, me hearties!\n" +
"There be Pirates nearby! Stations!\n";
for (var i = 1; i <= location.numRangers; i++) {
var ranger = location["ranger"+i];
var name = ranger.name;
var superblinder = location.weaponBulbs[ranger.station-1][0];
list += name + ", man the " + superblinder + "!\n";
}
alert(list);
}
dontPanic(lighthouseRock);