I'm new to javascript and I was making a simple program to reply
but the if statement doesn't work.
Here's my code :
var myInput = document.getElementById('myInput');
var myBtn = document.getElementById('btn');
var value = document.getElementById('myInput').value;
var answer = document.getElementById('answer');
var question = "Hi";
function message() {
if ( value == question) {
answer.innerHTML = "Hi, how can i help you?";
} else {
answer.innerHTML = "Hi ...";
}
}
and here's the html part:
<input id="myInput" type="text">
<button id="myBtn" type="button" onclick="message()">Send!</button>
<p id="answer"></p>
ifs work. Your data must be something other than what you expect. What debugging have you done?valueonly once from the input, at the start of the program, and then never updates even if you enter something into the input…