vendredi 18 août 2017

How to check 2 different types of things using ===?

I want to check whether the value in an input box is equal to a variable. When I use ===, it returns false but when I use ==, it returns true, provided both are equal.

<input id="g1"></input> <button id="b" onclick="myFunction()">Try</button>
function myFunction() {
var d1;
d1 = Math.floor(Math.random()*100)
if( document.getElementById("g1").value ==  d1) {
document.getElementById("d").innerHTML = "Correct";
}

Aucun commentaire:

Enregistrer un commentaire