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 trialAlexandre Gomes
4,775 PointsMy version
Hello, Am I doing it correctly ? I am thinking about including an if statement about the user input being 0, however it is not learned yet in this lesson so I guess that's it for now ?
// PROGRAM START
console.log("Program started")
// WELCOMES USER
name=prompt(
"Enter your name"
)
alert(
"Hi " + name + "!\n\In this script, you will be able to enter a number, then you will get a random number between 1 and that number.\n\ \n\Ready?"
)
// USER INPUT
userinput= prompt(
"Choose a number"
)
userinput= parseInt(userinput)
// ALERTS USER
alert(
"You've chosen " + userinput
)
// CALC RESULT
result = (
Math.random() * userinput
)
result= Math.floor(result) +1
// WRITE RESULT IN THE DOCUMENT
document.write(
"Your Random number is " + result
)
// PROGRAM END
console.log("Program ended")
2 Answers
Akhter Rasool
8,597 PointsYes, that's enough.
daviddiryawish
Full Stack JavaScript Techdegree Student 890 Pointsjust a question why did u use so much space?
just wondering.
mike sanford
2,389 Pointsmike sanford
2,389 PointsJust because I like feedback and you already have passed this point. Here is my code please comment if you read this.
var visitorNumber = prompt('Please enter a number between 1 and 10'); var enteredNumber = parseInt(visitorNumber); alert(enteredNumber); var randomNumGen = Math.floor(Math.random() * 6) +1; alert('Here is your random number ' + randomNumGen + ' based on the number you entered');