'JS Calculator for smokers
I'm working on a calculator for smokers and I can't figure out why he doesn't want to work. It's so simple and I don't see the mistake.
function spentMonth(){
let price;
let num;
num = Number(document.getElementById('vspent-month').value);
price = Number(document.getElementById('price').value);
let sumdays = Number(num) * 365;
let sum = Number(sumdays*price);
document.getElementById("rezult1").innerHTML = Number(sum).toFixed(2)+'<span class="dashicons dashicons-money-alt"></span>';
}
<div id="calcolate-cig">
<input placeholder="Years of smoking" id="spent-month" type="number" min="1" max="110" step="1" name="spent_month" value=""> *
<input placeholder="Money per day" id="price" type="number" min="0.1" step="0.1" name="spent_month"> = <button onclick="spentMonth()" type="submit" name="submit_1">Result</button>
<span class="rez" id="rezult1"></span>
</div>
Solution 1:[1]
Such a simple mistake and I couldn't see it. ID is wrong vspent-month - spent-month.
function spentMonth(){
let price;
let num;
num = Number(document.getElementById('spent-month').value);
price = Number(document.getElementById('price').value);
let sumdays = Number(num) * 365;
let sum = Number(sumdays*price);
document.getElementById("rezult1").innerHTML = Number(sum).toFixed(2)+'<span class="dashicons dashicons-money-alt"></span>';
}
<div id="calcolate-cig">
<input placeholder="Years of smoking" id="spent-month" type="number" min="1" max="110" step="1" name="spent_month" value=""> *
<input placeholder="Money per day" id="price" type="number" min="0.1" step="0.1" name="spent_month"> = <button onclick="spentMonth()" type="submit" name="submit_1">Result</button>
<span class="rez" id="rezult1"></span>
</div>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Tsvetomir Tsvetanov |
