I am a beginner Who just started a week ago. I’m trying to make a Mini Bet Game But I’m Keep getting Error in choco.money. It shows NaN everytime and not displaying any number. I tried Converting inputValue in Number Using Number() and ParseInt() but idk it still isnt Working.
Can You Please Point Out What am I Doing Wrong?
const rollButton = document.querySelector('.roll');
const resultText = document.querySelector('.resultText');
const winLose = document.querySelector('.winLose');
var inputMoney = document.querySelector('.money');
var inputMoney = document.querySelector('.counter');
const paise = {
win : 0,
lost:0,
money:500
};
let counter = 0;
rollButton.addEventListener('click', ()=> {randomizer()})
rollButton.addEventListener('click', ()=> {
console.log(counter++);
})
const totalMoney = paise.money;
function randomizer() {
const moneyValue = parseInt(inputMoney.value);
paise.money -= moneyValue;
var random = Math.random();
if (inputMoney.value === ''){
return;
}
else{
if(random >= 0.7 && random <= 0.9) {
//win
paise.win +=1;
resultText.innerHTML = `<span id="win">Money : $${moneyValue*2}</span><br> Total Money: ${totalMoney}`;
paise.money += moneyValue*2;
winLose.textContent = 'You Won';
}
else if(random > 0 && random < 0.7 ){
//Lose
paise.lost +=1;
paise.money += moneyValue*0;
resultText.innerHTML = `<span id="lose">Money : $${moneyValue*0}</span> <br> Total Money: ${totalMoney}`;
winLose.textContent = 'You Lost';
}
else if(random >= 0.99){
//jackpot
paise.money += moneyValue*10;
resultText.innerHTML = `<span id="bigWin">Money : $${moneyValue*10}</span> <br> Total Money: ${totalMoney}`;
winLose.textContent = 'You Won Jackpot';
}
}
console.log(choco);
}
I Tried Number() and ParseInt() to fix the issue of NaN but it didnt worked.
I am Expecting to Subtract the InputValue From choco.money before running the function. without any error.