Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Desmond Dallas
6,985 PointsExplanation for code
Can someone please explain the following line. Im not quite sure why the secret number is set to 10: parseInt (secretNumber, 10);
<!DOCTYPE>
<html lang="en"> <head> <title>Chapter 3, Example 3</title> </head> <body> <!--This code can be guessed for a guesses the correct answer--> <script> var secretNumber = prompt ("Pick a number between 1 and 5:", ""); secretNumber = parseInt (secretNumber, 10);
switch (secretNumber) {
case 1:
document.write("Too low!");
break;
case 2:
document.write("Too low!");
break;
case 3:
document.write("You guessed the secret number!");
break;
case 4:
document.write("Too high!");
break;
case 5:
document.write("Too high!");
break;
/* The default can be used to pick up bugs quickly. If it runs when it shouldnt be you have a bug*/ default: document.write("You did not enter a number between 1 and 5."); break; }
document.write("<br />Execution continues here"); </script> </body> </html>
2 Answers
Steven Parker
243,658 PointsThe 2nd argument to "parseInt" determine what numeric radix will be used when converting the digits. The number "10" means to use the decimal system. This is also the default used when only one argument is given.
The actual number returned by the conversion will be the numeric representation of what the user typed in answer to the prompt.
Desmond Dallas
6,985 PointsGreat thank you for the reply