Skip to content

Finished part 1-4#5

Open
martinhilary wants to merge 1 commit into
wdi-sg:masterfrom
martinhilary:master
Open

Finished part 1-4#5
martinhilary wants to merge 1 commit into
wdi-sg:masterfrom
martinhilary:master

Conversation

@martinhilary
Copy link
Copy Markdown

No description provided.

Comment thread script.js
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?

Comment thread script.js
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...

Comment thread script.js
}
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants