USER INPUT


How to accept user input


Easy way with a window prompt
Difficult way HTML textbox

(Easy way)

let username = window.prompt("What's your name?")
console.log(username)

(Difficult way using HTML)


Html

<label id="inputLabel">Enter you name </label>
<input type="text" id="inputText"> </input>
<button class="btn" type="button" id="inputButton">Submit</button>

Javascript

let username
document.getElementById("inputButton").onclick = function(){
username = document.getElementById("inputText").value
console.log(username)
document.getElementById("inputLabel").innerHTML = "Hello " + username
}

Monitor result ⬇️