-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCode-1-9.js
47 lines (43 loc) · 1.15 KB
/
Code-1-9.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
let powerOn=() => {
if(!ship.powerOn)ship.powerOn=true;
}
let countModules=() =>{
return availableModules.length;
}
let countEssential=() =>{
return availableModules.filter(function(module){
return module.essential;
} ).length;
}
let loadModule=(index,essential)=>{
if(index<0)throw new Error("Index must be positive");
let modCount=countModules();
if(index>modCount)throw new Error("Index must wthin 0 and " +modCount);
let module=availableModules[index];
module.enabled=true;
if(essential!==undefined)module.essential=essential;
ship.modules.push(module);
}
let findModuleIndex=(moduleName) =>{
return availableModules.findIndex(function(module){
return module.name==moduleName;
});
}
let loadModuleByName=(name,essential)=>{
loadModule(findModuleIndex(name,essential));
}
let resetLARRY=()=>{
for(let i=0; i<10;i++)LARRY.quack();
}
let _setMessage=(message)=>{
radio.message=message;
}
let setMessage=()=>{
_setMessage(JSON.stringify(navigation));
}
loadModuleByName("life-support");
loadModuleByName("propulsion",true);
loadModuleByName("navigation",true);
loadModuleByName("communication",true);
resetLARRY();
setMessage();