rep max calculator and I'm having a bit of an error with my calculation.
the formula for calculation is (((weight*reps)*0.0333)+weight)
const submit = document.querySelector('.submit');
let weight = document.querySelector('#weight');
let reps = document.querySelector('#reps');
submit.addEventListener('click', function() {
result = (((weight.value * reps.value) * 0.0333) + weight.value);
console.log(result);
})
<div class="cardbody">
<label for="weight"> Lift:</label>
<input class="input" id="weight" type="text" name="weight" placeholder="weight" required>
<label for="reps"> Reps:</label>
<input class="input" id="reps" type="text" name="Reps" placeholder="Repitions" required>
</div>
<div class="cardsubmit">
<button class="submit">Submit</button>
</div>
now I tried to manually enter my variables so in the javascript made the weight=165 and reps=6
the output that I'm expecting is 197.96 and what I'm getting is 32.967, what I noticed is that my program is not adding the weight at the end.(((weight*reps)*0.0333)+{{weight}}) << I put in double brackets
The problem here is that weight.value is a string
You need to convertIt to number to add it correctly I've used +weight.value but you can use parseInt instead
const submit = document.querySelector('.submit');
let weight= document.querySelector('#weight');
let reps= document.querySelector('#reps');
submit.addEventListener('click', function(){
result = +weight.value +(((weight.value * reps.value)*0.0333));
console.log(result);
})
<div class="cardbody">
<label for="weight"> Lift:</label>
<input class="input" id="weight" type="text" name="weight" placeholder="weight" required>
<label for="reps"> Reps:</label>
<input class="input" id="reps" type="text" name="Reps" placeholder="Repitions" required>
</div>
<div class="cardsubmit">
<button class="submit">Submit</button>
</div>