The browser’s console says:
TypeError: status.style is undefined, line 12
var status;
function output(msg,type="info"){
status.innerHTML=msg;
switch(type){
case "info":
status.style.background=undefined;
break;
case "warning":
status.style.background="#cccc33";
break;
case "error":
status.style.background="#ff0033";
break;
}
}
function init(){
status=document.getElementById("status");
output("Document loaded","error");
}
window.onload=init;
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" >
<title>Drag and drop upload</title>
<link href="css/style.css" rel="stylesheet" type="text/css" >
<script src="js/script.js" type="text/javascript"> </script>
</head>
<body>
<header>
<h1>Drag & drop upload</h1>
</header>
<div id="main">
<div id="status">Status</div>
<div id="inner"> </div>
</div>
<footer>© Copyright 2015</footer>
</body>
</html>
I know this is so simple and basic but I got no other choice but to ask. As I tested I think this is a scope error. So what’s the problem?