Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Javid 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,789 PointsAH yeah I see what you are saying.
Your are calling the function quiz() twice

Shawn Denham
Python Development Techdegree Student 17,789 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,789 Pointsyou're welcome :)

Shawn Denham
Python Development Techdegree Student 17,789 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,105 PointsJacob Mishkin
23,105 Pointsedited code for formatting.