I am creating a calculator but every time I run the res onclick code or the result object, it scrubs the whole page and I don’t understand why, I did everything possible but I couldn’t fix it, here I leave the code.
I know the error is based on Res.onclick and I think it is with the whiles, more explained they are made to verify how many multiplication, subtraction, addition and division symbols there are, I would like to know if there is a faster way too, well that was I hope that Can you help me solve this problem, I just started in this javascript and I think this is good to at least start, thanks.
var Boton_0 = document.getElementById("Num_0")
var Borrar = document.getElementById("Borrar")
var Boton_1 = document.getElementById("Num_1")
var Boton_2 = document.getElementById("Num_2")
var Boton_3 = document.getElementById("Num_3")
var Boton_4 = document.getElementById("Num_4")
var Boton_5 = document.getElementById("Num_5")
var Boton_6 = document.getElementById("Num_6")
var Boton_7 = document.getElementById("Num_7")
var Boton_8 = document.getElementById("Num_8")
var Boton_9 = document.getElementById("Num_9")
var Res = document.getElementById("Res")
var Suma = document.getElementById("Suma")
var Resta = document.getElementById("Resta")
var Multi = document.getElementById("Multi")
var Divi = document.getElementById("Div")
var Text_Num = document.getElementById("Text")
var Text_Res = document.getElementById("Result")
var Text_InMove = " "
function CambiarText_Num() {
Text_Num.innerHTML = Text_InMove
console.log(Text_InMove)
}
setInterval(CambiarText_Num, 100)
// Botones
Borrar.onclick = ()=> {
Text_InMove = Text_InMove.slice(1)
}
Boton_0.onclick = ()=> {
Text_InMove = "0".concat(Text_InMove)
}
Boton_1.onclick = ()=> {
Text_InMove = "1".concat(Text_InMove)
}
Boton_2.onclick = ()=> {
Text_InMove = "2".concat(Text_InMove)
}
Boton_3.onclick = ()=> {
Text_InMove = "3".concat(Text_InMove)
}
Boton_4.onclick = ()=> {
Text_InMove = "4".concat(Text_InMove)
}
Boton_5.onclick = ()=> {
Text_InMove = "5".concat(Text_InMove)
}
Boton_6.onclick = ()=> {
Text_InMove = "6".concat(Text_InMove)
}
Boton_7.onclick = ()=> {
Text_InMove = "7".concat(Text_InMove)
}
Boton_8.onclick = ()=> {
Text_InMove = "8".concat(Text_InMove)
}
Boton_9.onclick = ()=> {
Text_InMove = "9".concat(Text_InMove)
}
Suma.onclick = ()=> {
Text_InMove = "+".concat(Text_InMove)
}
Resta.onclick = ()=> {
Text_InMove = "-".concat(Text_InMove)
}
Multi.onclick = ()=> {
Text_InMove = "x".concat(Text_InMove)
}
Divi.onclick = ()=> {
Text_InMove = "÷".concat(Text_InMove)
}
// Resultado
Res.onclick = ()=>{
let Img_PC = Text_InMove
let Can = 0
let NoMas = false
let NoMas_2 = false
let NoMas_3 = false
let NoMas_4 = false
let MasListo = false
let MenListo = false
let Mulisto = false
while (NoMas == false){
let X = Img_PC.indexOf("+")
if (X == -1){
NoMas = true
MasListo = true
}
else {
Can++
}
}
while (NoMas_2 == false && MasListo == true){
let X = Img_PC.indexOf("-")
if (X == -1){
NoMas_2 = true
MenListo = true
}
else {
Can++
}
}
while (NoMas_3 == false && MenListo == true){
let X = Img_PC.indexOf("x")
if (X == -1){
NoMas_3 = true
Mulisto = true
}
else {
Can++
}
}
while (NoMas_4 == false && Mulisto == true){
let X = Img_PC.indexOf("÷")
if (X == -1){
NoMas_4 = true
}
else {
Can++
}
}
if (NoMas == true && NoMas_2 == true && NoMas_3 == true && NoMas_4 == true){
console.log(Can)
}
let Num_1
let Num_2
}