From ee504ff5ccc9cd07ebf52eaaa43a69d4fb44dda6 Mon Sep 17 00:00:00 2001 From: galoo5 <123580670+galoo5@users.noreply.github.com> Date: Sun, 4 Jun 2023 20:26:07 +0300 Subject: [PATCH 1/2] Initial commit --- README.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..dc80a6c --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# coursera-Coursera-HTML-CSS-and-JavaScript-for-Web-Developers \ No newline at end of file From 9d81f7cdd8eed84c26bc4d9de2d9051fa4e74ba6 Mon Sep 17 00:00:00 2001 From: galoo5 <123580670+galoo5@users.noreply.github.com> Date: Wed, 21 Jun 2023 20:22:53 +0300 Subject: [PATCH 2/2] Add files via upload --- SpeakGoodBye.js | 34 ++++++++++++++++++++++++++++++++++ SpeakHello.js | 32 ++++++++++++++++++++++++++++++++ index.html | 19 +++++++++++++++++++ script.js | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 134 insertions(+) create mode 100644 SpeakGoodBye.js create mode 100644 SpeakHello.js create mode 100644 index.html create mode 100644 script.js diff --git a/SpeakGoodBye.js b/SpeakGoodBye.js new file mode 100644 index 0000000..b568399 --- /dev/null +++ b/SpeakGoodBye.js @@ -0,0 +1,34 @@ +// NOTE! The steps in this file are basically identical to the ones you +// performed in the SpeakHello.js file. + +// STEP 6: Wrap the entire contents of SpeakGoodBye.js inside of an IIFE +// See Lecture 52, part 2 + + +// STEP 7: Create an object, called 'byeSpeaker' to which you will attach +// the "speak" method and which you will expose to the global context +// See Lecture 52, part 1 +// var byeSpeaker = + +// DO NOT attach the speakWord variable to the 'byeSpeaker' object. + + +// STEP 8: Rewrite the 'speak' function such that it is attached to the +// byeSpeaker object instead of being a standalone function. +// See Lecture 52, part 2 + + +// STEP 9: Expose the 'byeSpeaker' object to the global scope. Name it +// 'byeSpeaker' on the global scope as well. +// xxxx.xxxx = byeSpeaker; + + +(function(window) { + var speakWord = "Good Bye"; + var byeSpeaker = function (name) { + console.log(speakWord + " " + name); + } + + window.byeSpeaker = byeSpeaker; + +})(window); diff --git a/SpeakHello.js b/SpeakHello.js new file mode 100644 index 0000000..e56e2e2 --- /dev/null +++ b/SpeakHello.js @@ -0,0 +1,32 @@ +// STEP 2: Wrap the entire contents of SpeakHello.js inside of an IIFE +// See Lecture 52, part 2 + + +// STEP 3: Create an object, called 'helloSpeaker' to which you will attach +// the "speak" method and which you will expose to the global context +// See Lecture 52, part 1 +// var helloSpeaker = + +// DO NOT attach the speakWord variable to the 'helloSpeaker' object. + + +// STEP 4: Rewrite the 'speak' function such that it is attached to the +// helloSpeaker object instead of being a standalone function. +// See Lecture 52, part 2 + +// STEP 5: Expose the 'helloSpeaker' object to the global scope. Name it +// 'helloSpeaker' on the global scope as well. +// See Lecture 52, part 2 +// (Note, Step 6 will be done in the SpeakGoodBye.js file.) +// xxxx.xxxx = helloSpeaker; + + +(function(window) { + var speakWord = "Hello"; + var helloSpeaker = function (name) { + console.log(speakWord + " " + name); + } + + window.helloSpeaker = helloSpeaker; + +})(window); diff --git a/index.html b/index.html new file mode 100644 index 0000000..3bd903a --- /dev/null +++ b/index.html @@ -0,0 +1,19 @@ + + + + +
+ +open console to see the output
+ + + + + diff --git a/script.js b/script.js new file mode 100644 index 0000000..ce6d47c --- /dev/null +++ b/script.js @@ -0,0 +1,49 @@ +// ******************************* +// START HERE IF YOU WANT AN EASIER STARTING POINT FOR THIS ASSIGNMENT +// ******************************* +// +// Module 4 Assignment Instructions. +// +// The idea of this assignment is to take an existing array of names +// and then output either Hello 'Name' or Good Bye 'Name' to the console. +// The program should say "Hello" to any name except names that start with a "J" +// or "j", otherwise, the program should say "Good Bye". So, the final output +// on the console should look like this: +/* +Hello Yaakov +Good Bye John +Good Bye Jen +Good Bye Jason +Hello Paul +Hello Frank +Hello Larry +Hello Paula +Hello Laura +Good Bye Jim +WARNING!!! WARNING!!! +The code does NOT currently work! It is YOUR job to make it work +as described in the requirements and the steps in order to complete this +assignment. +WARNING!!! WARNING!!! +*/ + + +(function () { + +var names = ["Yaakov", "John", "Jen", "Jason", "Paul", "Frank", "Larry", "Paula", "Laura", "Jim"]; + +for (var i = 0; i < names.length; i++) { + var firstLetter = names[i].charAt(0).toLowerCase(); + + if (firstLetter === 'j') { + byeSpeaker(names[i]); + } + else { + helloSpeaker(names[i]); + } +} + +})(); + + +