12 Replies
'''js
<body>
<input type="number" placeholder="put" id="getter" >
<button onclick="submiter()" >do it</button>
<p id="shower"> </p>
<p id="brande"> </p>
<script>
let text = '';
ar = [1,2,3,4,5,6]
function submiter(){
let getter = document.getElementById('getter').value;
let random = ar[(Math.floor(Math.random() * ar.length))];
if(getter === random ){
text = random;
document.getElementById('brande').innerHTML = 'brande shodid ';
}else{
alert('bakhti')
}
document.getElementById('shower').innerHTML = text;
}
</script>
</body> ''' why when im using === not work? i want to something when i put correct random number in input it use it
</body> ''' why when im using === not work? i want to something when i put correct random number in input it use it
===
does a strict comparison, which includes type. .value
always returns a string, but your array has integers in it. So while 1 == '1'; //true
, 1 === '1'; //false
hmm
i dont get it
i cant use value with ===?
you can, but you'd have to compare against other strings, or convert your string into an integer
or just use
==
, that's probably fine in this case anywayi use == not work
ohh
it work
lol i was not lucky after 30 time attembd it alwse get another number
tnx for help == work
https://javascript.info/comparison here's more info on comparisons and strict comparisons
and on data types https://javascript.info/types
Tnx
btw fyi,
document.getElementById('getter').valueAsNumber
would return a numberI didn't even know valueAsNumber is even a thing lol
I always forget it exists
same