Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

JavaScript Create a condition with a integer random number

Bendito

Coder
Hello everyone!

I´m learnin by myself some javascript and I´m performing some exercises.

They ask me to create this:
"Generate a random integer number between 0 and 99 and assign it to the luck variable.

Write a condition that should check if Mr. Pink's luck is greater than 90. If so, the conditional statement should assign 'Mr. Purple' to alias. Otherwise, it should assign 'Mr. Pink'.

Print the alias value to the console."

They give this as an example:
JavaScript:
var speed;
var whatNow = speed < 80 ? 'BOOOM!' : 'Keep driving';
console.log(whatNow); // if speed is lower than 80 bus explodes; if not, you better keep driving

Also on the console they already provide me two variables, I need to complete the rest. I´m getting error messages regarding the creation of the integer number. In the past I did one time with this simple code, but now is not working, the console says "
>>>>Code is incorrect
Remember to generate a random number between 0 and 99. That number needs to be an integer."

JavaScript:
var someRandoNumber = Math.random()*42;
console.log(Math.ceil(Math.random()*42)

I created this code so far but I now it is wrong:
JavaScript:
var luck = RandomNumber;
var alias = luck < RandomNumber? 'Mr Pink´s': 'Mr Purple';
var RandomNumber = Math.random()*99;
console.log(Math.ceil(Math.random()*99));
console.log(alias);

Can anyone help me with this issue?

Thanks
Raquel
 
Here -
JavaScript:
var luck = Math.random()*99;
var alias = luck > 90 ? 'Mr Purple' : 'Mr Pink';
console.log(Math.ceil(luck));
console.log(alias);
 
Here -
JavaScript:
var luck = Math.random()*99;
var alias = luck > 90 ? 'Mr Purple' : 'Mr Pink';
console.log(Math.ceil(luck));
console.log(alias);

Hi Thanks for your help.

However the console keeps saying "
>>>>Code is incorrect
Remember to generate a random number between 0 and 99. That number needs to be an integer."

No ideia why the integer number keeps showing error!
 
Also print this
JavaScript:
var luck = Math.ceil(Math.random()*99);
var alias = luck < 90? 'Mr Purple' : 'Mr Pink';
console.log(Math.ceil(luck));
console.log(alias);

And the error is
>>>>Code is incorrect
Make sure the expressions on the left and right from the : sign are correct
 

New Threads

Buy us a coffee!

Back
Top Bottom