View Single Post
Old 03-31-2012, 05:53 PM   PM User | #6
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,044
Thanks: 197
Thanked 2,412 Times in 2,390 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Quote:
Originally Posted by HungryChapstick View Post
Say the user guessed correctly in their 1st or 2nd attempt, how would you get it to write, for example, "You guessed correctly on your 2nd attempt?"
Code:
if (guess == theNumber) {
var arr = ["", "first", "second", "third", "fourth"];  // note that the zeroth element of the array is blank.
message = "Well done! The number " + theNumber + " was correct!  This was your " + arr[i] + " attempt.";
i = tries;
}
I think you should solve the second question yourself, as you will only learn by doing things for yourself, rather than getting others to do your homework for you, but a hint is message += whatever which appends the new value to the existing value.
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.

Last edited by Philip M; 03-31-2012 at 05:59 PM..
Philip M is offline   Reply With Quote
Users who have thanked Philip M for this post:
HungryChapstick (03-31-2012)