Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 83 additions & 45 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
*/



Expand All @@ -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 =================================
Expand All @@ -62,14 +80,24 @@
// =======================================================================


/*
var x= Math.floor(Math.random() * 10) + 1
while(true)
{
if(x == y)
Copy link
Copy Markdown
Contributor

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?

{
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")
}







}
*/



Expand All @@ -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);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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...










*/



Expand All @@ -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);
*/
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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.




Expand Down Expand Up @@ -171,7 +209,7 @@ var Phonebook = {




var name=prompt("Who do you want to call?")



Expand Down