-
Notifications
You must be signed in to change notification settings - Fork 23
Finished part 1-4 #5
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,15 +10,12 @@ | |
| // ==================================================================== | ||
| // Write your solution below. | ||
| // ==================================================================== | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| /* | ||
| var x= prompt("Please enter one number") | ||
| var y =prompt("Please enter another number") | ||
| var z= Math.abs(x-y); | ||
| console.log("The difference in your numbers are " + z); | ||
| */ | ||
|
|
||
|
|
||
|
|
||
|
|
@@ -36,21 +33,42 @@ | |
| // ==================================================================== | ||
| // Write your solution below | ||
| // ==================================================================== | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| /* | ||
| var x= prompt("Enter an number") | ||
|
|
||
| function ordinal_suffix_of(i) { | ||
| var j = i % 10, | ||
| k = i % 100; | ||
| if (j == 1 && k != 11) { | ||
| return i + "st"; | ||
| } | ||
| if (j == 2 && k != 12) { | ||
| return i + "nd"; | ||
| } | ||
| if (j == 3 && k != 13) { | ||
| return i + "rd"; | ||
| } | ||
| return i + "th"; | ||
| } | ||
| var y= ordinal_suffix_of(x); | ||
|
|
||
| console.log("You are "+ y+ " place"); | ||
|
|
||
| */ | ||
| /* Jay's answer | ||
| var yes = prompt(“PART 2, Please input a number here: “); | ||
| var len = yes.length; | ||
|
|
||
| if ((len == 1) || (yes[len-2] != 1)) { | ||
| if (yes[len-1] == 1) { | ||
| console.log(yes + ‘st’); | ||
| } else if (yes[len-1] == 2) { | ||
| console.log(yes + ‘nd’); | ||
| } else if (yes[len-1] == 3) { | ||
| console.log(yes + ‘rd’); | ||
| } else console.log(yes + ‘th’); | ||
| } else console.log(yes + ‘th’); | ||
| */ | ||
|
|
||
|
|
||
| // ========================== Exercise 3 ================================= | ||
|
|
@@ -62,14 +80,24 @@ | |
| // ======================================================================= | ||
|
|
||
|
|
||
| /* | ||
| var x= Math.floor(Math.random() * 10) + 1 | ||
| while(true) | ||
| { | ||
| if(x == y) | ||
| { | ||
| alert("It matches!"); | ||
| break; | ||
|
|
||
| } | ||
| else | ||
| { | ||
| alert("Try again"); | ||
| var y= prompt("Hey boy give me one number from 1 to 10","Let's see whether it matches") | ||
| } | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| } | ||
| */ | ||
|
|
||
|
|
||
|
|
||
|
|
@@ -92,16 +120,19 @@ | |
|
|
||
|
|
||
|
|
||
| /* | ||
| var x=Math.random().toString(36).substring(6); | ||
| alert("This is your randomly generated alphanumeric string "+ x); | ||
| */ | ||
|
|
||
| /* | ||
| var y=prompt("Enter the ength of a random alphanumeric string"); | ||
| var length= parseInt(y); | ||
| var z=Math.random().toString(36).substring(length); | ||
| alert(z); | ||
|
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. Good trick to convert a random float into a base 36 string. But the length of the substrings returned are incorrect... |
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| */ | ||
|
|
||
|
|
||
|
|
||
|
|
@@ -114,14 +145,21 @@ | |
| // ==================================================================== | ||
| // Write your solution below. | ||
| // ==================================================================== | ||
|
|
||
| /* | ||
| var testArray = [1, 2, 4, 8, 16, 32, 64, 128]; | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| function shuffle(a) { | ||
| var j, x, i; | ||
| for (i = a.length - 1; i > 0; i--) { | ||
| j = Math.floor(Math.random() * (i + 1)); | ||
| x = a[i]; | ||
| a[i] = a[j]; | ||
| a[j] = x; | ||
| } | ||
| return a; | ||
| } | ||
| testArray=shuffle(testArray); | ||
| console.log(testArray); | ||
| */ | ||
|
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. Try to use more descriptive variable names as a matter of good coding practice. Code readability is important when working in teams, and any increase in file size is completely negated by pre-production compilers/optimizers. |
||
|
|
||
|
|
||
|
|
||
|
|
@@ -171,7 +209,7 @@ var Phonebook = { | |
|
|
||
|
|
||
|
|
||
|
|
||
| var name=prompt("Who do you want to call?") | ||
|
|
||
|
|
||
|
|
||
|
|
||
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.
I like that you thought of giving the user a chance to re-try the guessing part here.
It works, although a tip for improving this bit - the variable y is undeclared at line 87 the first time this runs. In stricter languages or other flavours of Javascript, this can throw an error. Next, this loop throws an alert for "Try again" even before the user has the chance to make his first guess.... why?