Skip to content

Commit 6660cf3

Browse files
committed
Add files via upload
1 parent 82b6af5 commit 6660cf3

File tree

4 files changed

+127
-0
lines changed

4 files changed

+127
-0
lines changed

Assignments/module-4/SpeakGoodBye.js

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// NOTE! The steps in this file are basically identical to the ones you
2+
// performed in the SpeakHello.js file.
3+
4+
// STEP 6: Wrap the entire contents of SpeakGoodBye.js inside of an IIFE
5+
// See Lecture 52, part 2
6+
7+
8+
// STEP 7: Create an object, called 'byeSpeaker' to which you will attach
9+
// the "speak" method and which you will expose to the global context
10+
// See Lecture 52, part 1
11+
// var byeSpeaker =
12+
13+
// DO NOT attach the speakWord variable to the 'byeSpeaker' object.
14+
15+
16+
// STEP 8: Rewrite the 'speak' function such that it is attached to the
17+
// byeSpeaker object instead of being a standalone function.
18+
// See Lecture 52, part 2
19+
20+
21+
// STEP 9: Expose the 'byeSpeaker' object to the global scope. Name it
22+
// 'byeSpeaker' on the global scope as well.
23+
// xxxx.xxxx = byeSpeaker;
24+
25+
26+
(function(window) {
27+
var speakWord = "Good Bye";
28+
var byeSpeaker = function (name) {
29+
console.log(speakWord + " " + name);
30+
}
31+
32+
window.byeSpeaker = byeSpeaker;
33+
34+
})(window);

Assignments/module-4/SpeakHello.js

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// STEP 2: Wrap the entire contents of SpeakHello.js inside of an IIFE
2+
// See Lecture 52, part 2
3+
4+
5+
// STEP 3: Create an object, called 'helloSpeaker' to which you will attach
6+
// the "speak" method and which you will expose to the global context
7+
// See Lecture 52, part 1
8+
// var helloSpeaker =
9+
10+
// DO NOT attach the speakWord variable to the 'helloSpeaker' object.
11+
12+
13+
// STEP 4: Rewrite the 'speak' function such that it is attached to the
14+
// helloSpeaker object instead of being a standalone function.
15+
// See Lecture 52, part 2
16+
17+
// STEP 5: Expose the 'helloSpeaker' object to the global scope. Name it
18+
// 'helloSpeaker' on the global scope as well.
19+
// See Lecture 52, part 2
20+
// (Note, Step 6 will be done in the SpeakGoodBye.js file.)
21+
// xxxx.xxxx = helloSpeaker;
22+
23+
24+
(function(window) {
25+
var speakWord = "Hello";
26+
var helloSpeaker = function (name) {
27+
console.log(speakWord + " " + name);
28+
}
29+
30+
window.helloSpeaker = helloSpeaker;
31+
32+
})(window);

Assignments/module-4/index.html

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
<!DOCTYPE html>
3+
<html>
4+
<head>
5+
<meta charset="utf-8">
6+
<title>Module 4 Solution </title>
7+
<script src="SpeakHello.js"></script>
8+
<script src="SpeakGoodBye.js"></script>
9+
<script src="script.js"></script>
10+
</head>
11+
<body>
12+
<h1>Module 4 Solution</h1>
13+
<p>open console to see the output</p>
14+
</body>
15+
</html>

Assignments/module-4/script.js

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// *******************************
2+
// START HERE IF YOU WANT AN EASIER STARTING POINT FOR THIS ASSIGNMENT
3+
// *******************************
4+
//
5+
// Module 4 Assignment Instructions.
6+
//
7+
// The idea of this assignment is to take an existing array of names
8+
// and then output either Hello 'Name' or Good Bye 'Name' to the console.
9+
// The program should say "Hello" to any name except names that start with a "J"
10+
// or "j", otherwise, the program should say "Good Bye". So, the final output
11+
// on the console should look like this:
12+
/*
13+
Hello Yaakov
14+
Good Bye John
15+
Good Bye Jen
16+
Good Bye Jason
17+
Hello Paul
18+
Hello Frank
19+
Hello Larry
20+
Hello Paula
21+
Hello Laura
22+
Good Bye Jim
23+
WARNING!!! WARNING!!!
24+
The code does NOT currently work! It is YOUR job to make it work
25+
as described in the requirements and the steps in order to complete this
26+
assignment.
27+
WARNING!!! WARNING!!!
28+
*/
29+
30+
31+
(function () {
32+
33+
var names = ["Yaakov", "John", "Jen", "Jason", "Paul", "Frank", "Larry", "Paula", "Laura", "Jim"];
34+
35+
for (var i = 0; i < names.length; i++) {
36+
var firstLetter = names[i].charAt(0).toLowerCase();
37+
38+
if (firstLetter === 'j') {
39+
byeSpeaker(names[i]);
40+
}
41+
else {
42+
helloSpeaker(names[i]);
43+
}
44+
}
45+
46+
})();

0 commit comments

Comments
 (0)