Answer the question
In order to leave comments, you need to log in
How to convert a string to a number so that the sum is calculated correctly?
There is a code
function makebet(){
var whatsyourbet = prompt("How much do you want to bet?");
var whatsyourbet2 = parseFloat(whatsyourbet);
var result = Math.floor(Math.random()*11);
if (result>5) {
document.querySelector("#rescas").innerHTML = "You have won! The result is "+result;
document.querySelector("#MoneyBalance").innerHTML +=whatsyourbet2;
};
}
Answer the question
In order to leave comments, you need to log in
//Если я вас правильно понял, то вам нужно сначала взять значение элемента
var a = document.querySelector("#MoneyBalance").innerHTML; //innerText
//сложить....
var res = parseFloat(a) + whatsyourbet2;
//а потом обратно вставляете
document.querySelector("#MoneyBalance").innerHTML = res; //либо сразу сложите здесь
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question