0

I am trying to make a command line, where when you type a command, such as 'bg green', the background turns green. Everything works okay except for when you type 'bg green', and press enter, nothing happens. The background stays black. This is my code:

<html>  
<body style="background-color:black" id="a">
<div style="width:100%;bottom:0px;height:30px;position:absolute;"></div>
<div id="commandline" onkeydown="if (event.keyCode == 13) command(); " style="-webkit-transform:rotate(0deg);font-family: 'Kelly Slab', cursive;z-index:2;background-color:black;height:36px;width:100%;bottom:0px;position:absolute;color:white;left:0px;font-size:20px;">
&gt
<input style="font-family:'Kelly Slab';color:white;height:100%;width:100%;background-color:black;border:none;position:absolute;font-size:30px;left:20px;top:0px;" id="cmdinput"></input>
<div id="commands"  style="z-index:1;background-color:black;height:100%;width:100%;bottom:36px;position:absolute;left:0px;"></div>
</body>
</html>    

<script type="text/javascript">

function command(){
if(document.getElementById('cmdinput').value.substring(0,9) == "bg green"{
document.getElementById('a').style.backgroundColor = 'green';
}
}

</script>    

I think the issue is with the javascript, but I'm not sure. Does anyone know what the issue is?

CJ Cohorst
  • 115
  • 7

2 Answers2

4

Missing closing bracket (after "bg green").

if(document.getElementById('cmdinput').value.substring(0,9) == "bg green") {
document.getElementById('a').style.backgroundColor = 'green';
}
Alex
  • 10,998
  • 6
  • 34
  • 52
2

Try this instead:

document.body.style.background = 'green';
Automate This
  • 28,343
  • 11
  • 54
  • 78