Hi, maybe I can help, you can check the live version here codesandbox
functionrandomNumber(){constgenerateRandom=()=>Math.floor(Math.random()*50)constnumber=generateRandom();returnnumber>10?number:number+10}functiongetLowerNumber(num){letgetGreaterNumber=randomNumber()while(getGreaterNumber>=num&&getGreaterNumber!==0){getGreaterNumber=randomNumber()}returngetGreaterNumber}constcakeMade=randomNumber()constcakeEat=getLowerNumber(cakeMade)document.getElementById("app").innerHTML=`
<h1>Q: I made ${cakeMade} cupcakes and ate ${cakeEat?cakeEat:'none'} of them. How many am i left with?</h1>
<h1>A: ${cakeEat===0?'I don`t need to do any calculations.':cakeMade-cakeEat}</h1>
`;
Using a while loop to generate a number of eaten cupcakes smaller than the amount made is unnecessary, it's better to generate the amount of cupcakes and then use that number as the ceiling for the amount of eaten cupcakes.
Hi, maybe I can help, you can check the live version here codesandbox
Using a
while
loop to generate a number of eaten cupcakes smaller than the amount made is unnecessary, it's better to generate the amount of cupcakes and then use that number as the ceiling for the amount of eaten cupcakes.Yes it's make sense to use start-end range for eaten and or made cakes and should be better. Already updated my code on sandbox