I'm getting NaN
despite using parseInt
or .value
, and I don't understand why is that. I also tried changing the code, but then im getting undefined
.
As a beginner I don't get what I'm doing wrong despite it being so simple. Any tips?
const btn = document.querySelector('.btn');
btn.addEventListener('click',calcWinner);
function calcWinner(e){
const powerG = document.querySelector('#power-g');
const techG = document.querySelector('#tech-g');
const chanceG = document.querySelector('#chance-g');
const powerF = document.querySelector('#power-f');
const techF = document.querySelector('#tech-f');
const chanceF = document.querySelector('#chance-f');
let gokuR = parseInt(powerG + techG + chanceG)
let friezeR = parseInt(powerF.value) + parseInt(techF.value) + parseInt(chanceF.value);
console.log(parseInt(gokuR.value));
}
<body>
<div class="container">
<div class="goku">
<h2>Battle chance</h2>
<form action="">
<input type="number" name="" id="power-g" >
<label for="power-g">Power</label>
<input type="number" name="" id="tech-g" >
<label for="tech-g">Technique</label>
<input type="number" name="" id="chance-g" >
<label for="chance-g">Chance</label>
</form>
</div>
<div class="frieza">
<h2>Battle chance</h2>
<form action="">
<input type="number" name="" id="power-f" >
<label for="power-f">Power</label>
<input type="number" name="" id="tech-f" >
<label for="tech-f">Technique</label>
<input type="number" name="" id="chance-f" >
<label for="chance-f">Chance</label>
</form>
</div>
</div>
<h1 >Winner : <span class="winner"></span></h1>
<a href="#" class="btn">CalcWinner</a>
<script src="app.js"></script>
</body>