I have to code a website, I have my homepage and I want to add an input in my HTML and to add in my JavaScript a function who check if the word is the same in Javascript.
It just need to check if the input is "nsi", and then return "right".
This website is just for me, in local. So I don’t need php, sql or other language.
function secret() {
var secretInput = document.getElementById("secret").value;
var mot = "nsi";
console.log("secretInput");
if (secretInput === mot) {
var bravo = document.getElementById('bravo');
bravo.innerHTML = "right";
}
}
<div class="secretword" id="english">
<p>
Clues have been placed on the different pages to form a word, find it!
<input id="secret" autocomplete="off">
<button onclick="secret()">Done</button>
</p>
</div>
3
Answers
You are missing an element with id="bravo"
add for example
and it’ll work
You haven’t called any tag in your HTML with the "bravo" tag, so JS won’t find any element with that id and will return an error:
If you want to add a new paragraph tag for the action.
Do you have an element in your html with the id "bravo" ? make sure to have that.
and in your console.log statement you are logging the string "secretInput" , if you want to log the variable’s value you should use secretInput without quotes