Here’s the code:
function numCheck(n) {
const selectedNum = n
if(selectedNum >= 1 && selectedNum <= 10) {
return selectedNum
} else {
return false
}
}
function numRandomizer(userNum) {
const minValue = Math.ceil(1)
const maxValue = Math.floor(10)
const randInt = Math.floor(Math.random() * (maxValue - minValue) + minValue)
console.log(randInt)
if(randInt == userNum) {
return 'Congratulations, you won!'
} else {
return 'Sorry, you lost!'
}
}
const result = numRandomizer(numCheck(5))
console.log(result)
It’s working but I don’t think it’s well written. I had some problems to figure it out how to pass the selectedNum variable value to the numRandomizer function. Is there a better way of doing it?