How do I make my code result in 50/50?


#1

Let’s say I use Math.random and Math.floor to generate a number between 1 - 10. If it produces an even number I want to it run a certain statement like document.write(‘you win’). If it’s odd, then I want it to run another statement such as document.write(‘you lose’). I tried making a variable equal to an array and putting the even numbers in it but I couldn’t find a way to make it write a statement if one thing in the array is true.


#2

math.random generates random number between 0 and 1, so to get 50%, you will simply need to check if the random is less then 0.5