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 trial

JavaScript JavaScript Basics (Retired) Working With Numbers The Random Challenge

Alexandre Gomes
Alexandre Gomes
4,775 Points

My 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")

Just 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');

2 Answers

Akhter Rasool
Akhter Rasool
8,597 Points

Yes, that's enough.