These are chat archives for FreeCodeCamp/Help

18th
Mar 2019
nsonhouse
@nsonhouse
Mar 18 01:55
Hello all. I need some help with a bug in my code. Any takers?
``````<body>

<div id="guess">
<label>Enter a number</label>
<input type="number" id="guessNum">
<button id="btn">CLICK</button>
</div>

<div id="output">
<!-- output here -->
</div>

<script>
let randNum = Math.floor(Math.random() * 10) + 1;
document.getElementById("btn").addEventListener("click", isCorrect);

function isCorrect() {
let gn = document.getElementById("guessNum").value;

if(gn === randNum){
document.getElementById("output").innerHTML = "Good Work!";
alert(gn +" "+ randNum);
}
else{
document.getElementById("output").innerHTML = "No Match! The number is: " + randNum;
alert(gn +" "+ randNum);
}
}
</script>
</body>``````
nsonhouse
@nsonhouse
Mar 18 02:02
The value from the input box never matches the random number. I have determined what the random number is from the console, and still never get a match.
Christopher McCormack
@cmccormack
Mar 18 02:50
@nsonhouse the input is a string, you should either convert to a number or use loose equality `==` instead of `===`
Christopher McCormack
@cmccormack
Mar 18 02:55
@nsonhouse also `let randNum = Math.floor(Math.random() * 10) + 1;` can be written `let randNum = Math.ceil(Math.random() * 10);`
nsonhouse
@nsonhouse
Mar 18 02:56
@cmccormack So input type="number" is a string?
Christopher McCormack
@cmccormack
Mar 18 03:01
@nsonhouse the value is, yes
nsonhouse
@nsonhouse
Mar 18 03:02
@cmccormack OK. I thought the input type forces the data type in the field?
Like text, number, date, email, etc...
Christopher McCormack
@cmccormack
Mar 18 03:04
that only affects what you see in the input on the page, but as far as getting information from an html element via JavaScript they are all strings
nsonhouse
@nsonhouse
Mar 18 03:14
@cmccormack WOW!!! Good stuff man!!! Thank you!!!
henryking123
@henryking123
Mar 18 04:58
Hello, can I ask here for help for a website I'm developing?
It's about flexbox.
zootechdrum
@zootechdrum
Mar 18 07:26
hello quick question
``````x = [1,2,3,4,5]

for x[-2] in x:
print(x[-2])``````
gives me
1
2
3
3
5
what is x[-2]
Momozor
@momozor
Mar 18 19:50
hi
May Kittens Devour Your Soul
@diomed
Mar 18 20:21
@henryking123 dont ask if you can ask. just ask