I can't wrap my head around a piece of code using loops and functions in javascript. I have a function which generates random numbers (between a min and max), see below:
const getRandomNumber = (min, max) => {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}
Below a simple Function which returns true if 2 random numbers add up to 10, else it returns false:
const Function1 = (n1, n2) => (n1 + n2 === 10) ? true : false
Below i will use Function1 to return n1 and n2:
const Function1Check= () => {
const n1 = getRandomNumber(-10, 10);
const n2 = getRandomNumber(-10, 10);
if(Function1(n1, n2)) {
return [n1, n2]
} else {
return {false}
}
}
const LoopFunction = () => {
while(Function1Check === false) {
Function1Check();
if(Function1Check) {break;}
}
}
My while loop does not work correctly, what am i missing? Hope you guys can help me out and point me in the right direction using vanilla javascript. Thanks in advance.
Greetings.
whileloop doesn't return anything, please show your loop, and be specific when describing the problem.