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 trialYonas Mulyadi
8,000 PointsHow about this code of mine?
var randomNumber = getRandomNumber(10); var guess; var guessCount = 0;
function getRandomNumber( upper ) { var num = Math.floor(Math.random() * upper) + 1; return num; }
do { guess = parseInt(prompt (' I\'m thinking of a number, please think')); guessCount += 1; } while( guess !== randomNumber); document.write ('<p> ' + 'Good job! </p>'); document.write ('you have succesfully guessed the number in ' + guessCount + ' attempts');
2 Answers
Steven Parker
231,268 PointsI'm not sure what you're asking, but at first glance this code appears to be complete and correct. Good job.
Tip: You can avoid escaping apostrophes by enclosing strings in quote marks instead: "Here's an example"
And for future posts with code, be sure to use the instructions for code formatting in the Markdown Cheatsheet pop-up below the "Add an Answer" area. Or watch this video on code formatting.
Johnnt Trav
Courses Plus Student 1,295 PointsLooking great!
Yonas Mulyadi
8,000 PointsYonas Mulyadi
8,000 PointsWhoaaa, thanks for the response sir. As for the code formatting rules, I'll read it immediately.
Steven Parker
231,268 PointsSteven Parker
231,268 PointsBonus tip: You never need concatenation with two literal strings. Just write them as one string:
"<p> Good job! </p>"