Creating a chance miss system. Any help for a newbie? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Creating a chance miss system. Any help for a newbie?

Hi guys, I’m new to coding and am trying to do something but can’t seem to figure out how. The basic code: Var z=pickRandom(2) For(var I=100,I>0,i-20) if(z<2) print I Else Print(‘miss’) if(I===0) print (‘done’) what I want to have happen is if z=1 it prints I and if it doesn’t it does not subtract 20 from I. After it loops once I want it to repick z and loop again. The outcome should look something like: 100 Miss Miss 80 60 40 Miss 20 Miss Miss Done I know this is not the easiest but any help would be appreciated.

4th Nov 2019, 7:57 PM
Merrix Murphy
Merrix Murphy - avatar
2 Answers
+ 2
JME Math.ceil
5th Nov 2019, 6:53 AM
Gordon
Gordon - avatar
+ 1
Math.floor(Math.random() * 2) + 1; is how to generate a random number between 1&2, this needs to go in the loop so a new number is picked every iteration. If you need more help please reply with a link to your attempt in a code playground
4th Nov 2019, 8:49 PM
JME