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 trialJavid Abbasov
9,243 PointsWhy does it show alert box 2 times?
Here is my code.
function quiz() {
a = parseInt(prompt("Type the lowest possible value"));
b = parseInt(prompt("Type the highest possible value"));
result = Math.floor(Math.random() * (b - a + 1)) + a;
return result;
}
quiz();
document.write("Your number is " + quiz());
2 Answers
Shawn Denham
Python Development Techdegree Student 17,802 PointsAH yeah I see what you are saying.
Your are calling the function quiz() twice
Shawn Denham
Python Development Techdegree Student 17,802 Pointsfunction quiz() {
a = parseInt(prompt("Type the lowest possible value"));
b = parseInt(prompt("Type the highest possible value"));
result = Math.floor(Math.random() * (b - a + 1)) + a;
return result;
}
quiz(); //you don't need to call quiz() here...you are just calling it and not doing anything with it
document.write("Your number is " + quiz()); //since you are calling quiz() here for use in your document.write statement
Javid Abbasov
9,243 Pointsthank u)
Shawn Denham
Python Development Techdegree Student 17,802 Pointsyou're welcome :)
Shawn Denham
Python Development Techdegree Student 17,802 PointsYou have 2 prompt statements.
a = parseInt(prompt("Type the lowest possible value"));
b = parseInt(prompt("Type the highest possible value"));
Javid Abbasov
9,243 Pointsno, after these 2 times, it asks 2 times again. just try it and you will see
Jacob Mishkin
23,118 PointsJacob Mishkin
23,118 Pointsedited code for formatting.