-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
34 lines (24 loc) · 918 Bytes
/
Copy pathscript.js
File metadata and controls
34 lines (24 loc) · 918 Bytes
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
// Module 4 Assignment
// STEP 1:
// Wrap the entire contents of script.js inside of an IIFE
(function(window) {
var names = ["Yaakov", "John", "Jen", "Jason", "Paul", "Frank", "Larry", "Paula", "Laura", "Jim"];
// STEP 10:
// Loop over the names array and say either 'Hello' or "Good Bye"
// using the 'speak' method of either helloSpeaker or byeSpeaker
for (var i = 0; i < names.length; i++) {
name = names[i];
var firstLetter = name.charAt(0);
// STEP 12:
// Compare the 'firstLetter' retrieved in STEP 11 to lower case
// 'j'. If the same, call byeSpeaker's 'speak' method with the current name
// in the loop. Otherwise, call helloSpeaker's 'speak' method with the current
// name in the loop.
if (firstLetter.toLowerCase() == "j") {
byeSpeaker.speak(name);
}
else {
helloSpeaker.speak(name);
}
}; // end of for loop
}) (window);