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 trialAhmed Hassan
5,533 PointsCheck out my program
Dave McFarland Check out my program and tell me your comments..
var VisitorName=prompt("What's your name, Visitor?"); VisitorName+="!" alert("Hello "+VisitorName+"."); var yes_no=prompt("Do you want to play a random number game? (Yes or No)"); if (yes_no.toLowerCase()==="yes") { alert("You need to choose two numbers so the program will generate a random number that lies in between"); var StartingNum=prompt("Please input the Starting Number"); var EndingNum=prompt("Please input the Ending number"); StartingNum=parseInt(StartingNum); EndingNum=parseInt(EndingNum); if (StartingNum>EndingNum) { alert("Wrong Entry! "+"The Starting Number must be less than the Ending Number. "+"Please reload the page to rerun the program"); } else { document.write(Math.ceil((Math.random()*(EndingNum-StartingNum))+StartingNum)+" is a random number between " + StartingNum + " and " + EndingNum + "."); } } else if (yes_no.toLowerCase()==="no") { alert("Thank you for visiting!"); } else { alert("Wrong Entry! Please reload the page to try again."); }
2 Answers
Daniel Newman
Courses Plus Student 10,715 Pointsvar VisitorName = prompt("What's your name, Visitor?"); // "Bob"
VisitorName += "!" // "Bob!"
alert("Hello " + VisitorName + "."); // "Hello Bob!."
var yes_no = prompt("Do you want to play a random number game? (Yes or No)");
if (yes_no.toLowerCase() === "yes") {
alert("You need to choose two numbers so the program will generate a random number that lies in between");
var StartingNum = prompt("Please input the Starting Number");
var EndingNum = prompt("Please input the Ending number");
StartingNum = parseInt(StartingNum);
EndingNum = parseInt(EndingNum);
if (StartingNum > EndingNum) {
alert("Wrong Entry! "
+ "The Starting Number must be less than the Ending Number. "
+ "Please reload the page to rerun the program"); // What about 0 and 0 or 7 and 7?
} else {
document.write(Math.ceil( Math.random() * ( EndingNum - StartingNum )
+ StartingNum + " is a random number between "
+ StartingNum + " and " + EndingNum + ".");
}
} else if (yes_no.toLowerCase() === "no") {
alert("Thank you for visiting!");
} else {
alert("Wrong Entry! Please reload the page to try again.");
}
The code is no a song. First you have to do is a plan. There was some trouble with parenthis and logic of application is not clear. A bit later you will hear about KISS and DRY method of development that will make your code cleaner and efficient.
Ahmed Hassan
5,533 PointsThank you for your advice.