In this page javascript prompt works only if directly called in body section, if we try to call functions show() or showIN(), the first in head section, the second in body section, the var is undefined. Why ?
<!DOCTYPE html>
<html>
<head>
<script>
//called by button 2 "show" : doesn't work, u=undefined
function show(){
var u = prompt("What 3 ?");
alert("u = "+ u);
alert("qu = "+ qu);
}
</script>
</head>
<body onload= "show();">
<script>
// this works:
var qu = prompt("What 1 ?");
alert("qu = "+ qu);
// called by button two "showIN": doesn't work, w=undefined
function showIN(){
var w = prompt("What 4 ?");
alert("qu = "+ qu);
alert("w = "+ w);
}
</script>
<button id = "one" onClick = "show();">show</button>
<br/>
<button id = "two" onClick = "showIN();">showIN</button>
</body>
</html>