Personal as I can do for when I click instead of changing the number insert 1 more number, as a calculator for example

Asked

Viewed 27 times

-1

var b1=[]
var b2=[]
var b3=[]
var b4=[]
var b5=[]
var b6=[]
var b7=[]

function botao1() {
   b1=1
   document.getElementById('resultado').innerHTML=b1

    
}
function botao2(){
   b2=2
   document.getElementById('resultado').innerHTML=b2

}
function botao3() {
    b3=3
    document.getElementById('resultado').innerHTML=b3
}
function botao4() {
    b4=4
    document.getElementById('resultado').innerHTML=b4

}
function botao5() {
   
    b5=5
    document.getElementById('resultado').innerHTML=b5
}
function botao6() {
    b6=6
    document.getElementById('resultado').innerHTML=b6
}
function botao7() {
      b7=7
     document.getElementById('resultado').innerText=b7
}

function res() {
    if (b1+b6==17) {document.getElementById('candidato').innerHTML='bolsonaro'
        
    }
}

function soma() {
  
}

1 answer

-1

Javascript is a weakly typed language, so when you define a variable as follows: B1=1; B7=7; these variables will be receiving a numeric type value.

What you want to do in your case is to perform a concatenation between two strings and compare them with another string.

Try to accomplish this way:

var b1=[]
var b2=[]
var b3=[]
var b4=[]
var b5=[]
var b6=[]
var b7=[]

function botao1() {
   b1='1'
   document.getElementById('resultado').innerHTML=b1

    
}
function botao2(){
   b2='2'
   document.getElementById('resultado').innerHTML=b2

}
function botao3() {
    b3='3'
    document.getElementById('resultado').innerHTML=b3
}
function botao4() {
    b4='4'
    document.getElementById('resultado').innerHTML=b4

}
function botao5() {
   
    b5='5'
    document.getElementById('resultado').innerHTML=b5
}
function botao6() {
    b6='6'
    document.getElementById('resultado').innerHTML=b6
}
function botao7() {
      b7='7'
     document.getElementById('resultado').innerText=b7
}

function res() {
    if (b1+b6=='17') {document.getElementById('candidato').innerHTML='bolsonaro'
        
    }
}

function soma() {
  
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.