-
Notifications
You must be signed in to change notification settings - Fork 23
done 1,3,4,5,6 #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jodich
wants to merge
1
commit into
wdi-sg:master
Choose a base branch
from
jodich:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
done 1,3,4,5,6 #11
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,56 +1,9 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
| <meta http-equiv="X-UA-Compatible" content="ie=edge"> | ||
| <title>JS Exercise - 31 May 2018</title> | ||
| <link href="https://fonts.googleapis.com/css?family=Orbitron" rel="stylesheet"> | ||
| <style> | ||
| body { | ||
| background-color: darkslategrey; | ||
| } | ||
|
|
||
| #clock { | ||
| font-family: 'Orbitron', sans-serif; | ||
| font-size: 5em; | ||
| color: green; | ||
| background-color: black; | ||
| width: 8em; | ||
| height: 3em; | ||
| line-height: 3em; | ||
| text-align: center; | ||
| margin: 1em auto; | ||
| border-radius: 2em; | ||
| } | ||
| </style> | ||
| </head> | ||
| <body> | ||
| <div id="clock"></div> | ||
| <script src="./script.js"></script> | ||
| <script> | ||
| var clocky = document.getElementById('clock'); | ||
| var endTime = '10:15:00 AM'; | ||
|
|
||
| clocky.innerHTML = new Date().toLocaleT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qVX2a/EEBUdU1KrXLf40GoiiFXK///qpoiDXrOgqDR38JB0bw7SoL+ZB9o1RCkQjQ2CBYZKd/+VJxZRRZlqSkKiws0WFxUyCwsKiMy7hUVFhIaCrNQsKkTIsLivwKKigsj8XYlwt/WKi2N4d//uQRCSAAjURNIHpMZBGYiaQPSYyAAABLAAAAAAAACWAAAAApUF/Mg+0aohSIRobBAsMlO//Kk4soosy1JSFRYWaLC4qZBYWFRGZdwqKiwkNBVmoWFSJkWFxX4FFRQWR+LsS4W/rFRb/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////VEFHAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAU291bmRib3kuZGUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMjAwNGh0dHA6Ly93d3cuc291bmRib3kuZGUAAAAAAAAAACU="); | ||
| snd.play(); | ||
| }; | ||
|
|
||
| function updateTime() { | ||
| var time = new Date().toLocaleTimeString(); | ||
| clocky.innerHTML = time; | ||
| if (time === endTime) { | ||
| clearInterval(timer); | ||
| clocky.style.backgroundColor = 'red'; | ||
| clocky.style.color = 'white'; | ||
| beep(); | ||
| }; | ||
| }; | ||
|
|
||
| var timer = setInterval(updateTime, 1000); | ||
| </script> | ||
| </body> | ||
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,18 +11,12 @@ | |
| // Write your solution below. | ||
| // ==================================================================== | ||
|
|
||
| /* --answer here | ||
|
|
||
| var secondNum = prompt("Give me another number!") | ||
| console.log(Math.abs(firstNum - secondNum)) | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| */ | ||
|
|
||
| // ========================== Exercise 2 ============================== | ||
| // Prompt the user for a number, then console.log its ordinal version. | ||
|
|
@@ -37,19 +31,8 @@ | |
| // Write your solution below | ||
| // ==================================================================== | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| // method 1: use switch | ||
| // method 2 : determine the 2nd last value of the string | ||
|
|
||
|
|
||
|
|
||
|
|
@@ -62,18 +45,18 @@ | |
| // ======================================================================= | ||
|
|
||
|
|
||
| /* -- answer here | ||
|
|
||
| var userNum = parseInt(prompt("Give me a number from 0 to 10!")); | ||
| var genNum = Math.floor(Math.random() * 11); | ||
|
|
||
| if (userNum === genNum) { | ||
| console.log("Yay! Your number matched!") | ||
| } else { | ||
| console.log("Your numbers did not match! :( ") | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| */ | ||
|
|
||
|
|
||
| // ========================== Exercise 4 =============================== | ||
|
|
@@ -91,18 +74,15 @@ | |
|
|
||
|
|
||
|
|
||
| // var possible = "ABCDEFGHIJKLMNOPQRSTUVabcdefghigklmnopqrstuvwxyz0123456789" | ||
| // var results = "" | ||
|
|
||
| // for (var i = 0; i < 6; i++) { | ||
| // var gen = possible[Math.floor(Math.random() * 62)]; | ||
| // results += gen; | ||
| // } | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| // console.log(results); | ||
|
|
||
|
|
||
|
|
||
|
|
@@ -115,25 +95,17 @@ | |
| // Write your solution below. | ||
| // ==================================================================== | ||
|
|
||
| var testArray = [1, 2, 4, 8, 16, 32, 64, 128]; | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| // var testArray = [1, 2, 4, 8, 16, 32, 64, 128]; | ||
| // var randomArray = []; | ||
|
|
||
| // // !!! ask, why the numbers come out so weirdly in the console | ||
| // for (i=0; testArray.length > 0; i++) { | ||
| // var randomArrayIndex = Math.floor(Math.random() * testArray.length); | ||
| // var randomArrayValue = testArray.splice(randomArrayIndex, 1); | ||
| // randomArray.push(randomArrayValue); | ||
| // } | ||
|
|
||
| // console.log(randomArray) | ||
|
|
||
|
|
||
| // ========================== Exercise 6 ============================== | ||
|
|
@@ -168,17 +140,68 @@ var Phonebook = { | |
| "Nelson Tan" : 63396565 | ||
| }; | ||
|
|
||
| // // ---- part 1 | ||
| // var inputName = prompt("Give me a name: Jason, Amelie, Sing An, Ong Tng Kai, Nelson Tan") | ||
|
|
||
| // if (Phonebook[inputName]) { | ||
| // console.log(Phonebook[inputName]); | ||
| // } else { | ||
| // console.log("Not valid input"); | ||
| // } | ||
|
|
||
| // // ---- part 2 | ||
| // var inputName = prompt("Give me a name"); | ||
| // var inputNum = parseInt(prompt("Give me a new num")); | ||
|
|
||
| // var eachName = Object.keys(Phonebook); | ||
|
|
||
| // for (i=0; i < eachName.length; i++) { | ||
| // if (eachName[i] === inputName) { | ||
| // //update number | ||
| // Phonebook[inputName] = inputNum; | ||
| // console.log(inputName + "\'s new number is " + inputNum); | ||
| // } | ||
| // } | ||
|
|
||
| // console.log(Phonebook); | ||
|
|
||
| // // ---- part 3 | ||
|
|
||
| // var inputName = prompt("Give me a name"); | ||
| // var inputNum = parseInt(prompt("Give me a new num")); | ||
|
|
||
| // var eachName = Object.keys(Phonebook); | ||
| // var eachNum = Object.values(Phonebook); | ||
|
|
||
| // for (i=0; i < eachName.length; i++) { | ||
| // if (eachName[i] !== inputName) { | ||
| // //update number | ||
| // Phonebook[inputName] = inputNum; | ||
| // console.log(inputName + "\'s number is " + inputNum); | ||
| // break; | ||
| // } | ||
| // } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The instructions inside the if{} block are going to be run multiple times, because the condition eachName[i] !== inputName is going to return true most of the time. Testing for conditions inside a loop is something that has to be handled with care. |
||
|
|
||
| // console.log(Phonebook); | ||
|
|
||
| // // ---- part 4 | ||
|
|
||
| // var inputName = prompt("Give me a name: Jason, Amelie, Sing An, Ong Tng Kai, Nelson Tan"); | ||
| // delete Phonebook[inputName]; | ||
| // console.log(Phonebook); | ||
|
|
||
| // ---- bonus | ||
|
|
||
| var inputNum = parseInt(prompt("Give me a num")); | ||
|
|
||
| var eachName = Object.keys(Phonebook); // eachName = ["Jason", "Amelie", "Sing An", "Ong Tng Kai", "Nelson Tan"] | ||
| var eachNum = Object.values(Phonebook); // eachNum = [91216599, 64239839, 85404834, 94547788, 63396565] | ||
|
|
||
| for (i=0; i < eachNum.length; i++) { | ||
| if (eachNum[i] === inputNum) { | ||
| console.log(eachName[i]); | ||
| } | ||
| } | ||
|
|
||
|
|
||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I'm seeing the same output as you are, you're seeing something like [ [1], [4], [128], ... ] right? That's because each element in that output array is an array itself, consisting of a single element. That means that your last line, randomArray.push(randomArrayValue), is actually pushing arrays into the randomArray...