I\'m trying to get a number from an input box, but it returns an empty string as an alert. What do I miss?
You need to read the value of the input inside the function, not during page load. The following code will work.
var button = document.getElementsByClassName("btn")[0];
button.addEventListener("click", calculate);
function calculate() {
var num = document.getElementById("input").value;
alert(num);
}