I am a beginner in programming with javascript and I am having a problem with shortening up this switch statement? I want the user to be able to type in a hour of the day from 1-24. when you type 5-11 script runs good morning, 12-18 script runs good afternoon, 19-24 and 1-4 script runs good evening. My code works but it is way to long, if someone can give me a tip, I would really appreciate it. thanks alot.
<?xml version = “1.0” encoding = “utf-8”?>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN”
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”>
<!-- XHTML Template -->
<html xmlns = “http://www.w3.org/1999/xhtml”>
<head>
<title>Time of Day</title>
<script type =“text/javascript”>
<!–
var time; // user's choice
var validInput = true; // indicates if input is valid
var greeting; // type of list as a string
time = window.prompt( "Please type in what hour of the day it is.
(example: 1 - 24)" );
switch ( time )
{
case "5":greeting = "<h1>Good Morning!</h1>";
break;
case "6":greeting = "<h1>Good Morning!</h1>";
break;
case "7":greeting = "<h1>Good Morning!</h1>";
break;
case "8":greeting = "<h1>Good Morning!</h1>";
break;
case "9":greeting = "<h1>Good Morning!</h1>";
break;
case "10":greeting = "<h1>Good Morning!</h1>";
break;
case "11":greeting = "<h1>Good Morning!</h1>";
break;
case "12":greeting = "<h1>Good Afternoon!</h1>";
break;
case "13":greeting = "<h1>Good Afternoon!</h1>";
break;
case "14":greeting = "<h1>Good Afternoon!</h1>";
break;
case "15":greeting = "<h1>Good Afternoon!</h1>";
break;
case "16":greeting = "<h1>Good Afternoon!</h1>";
break;
case "17":greeting = "<h1>Good Afternoon!</h1>";
break;
case "18":greeting = "<h1>Good Afternoon!</h1>";
break;
case "19":greeting = "<h1>Goood Evening!</h1>";
break;
case "20":greeting = "<h1>Goood Evening!</h1>";
break;
case "21":greeting = "<h1>Goood Evening!</h1>";
break;
case "22":greeting = "<h1>Goood Evening!</h1>";
break;
case "23":greeting = "<h1>Goood Evening!</h1>";
break;
case "24":greeting = "<h1>Goood Evening!</h1>";
break;
case "1":greeting = "<h1>Goood Evening!</h1>";
break;
case "2":greeting = "<h1>Goood Evening!</h1>";
break;
case "3":greeting = "<h1>Goood Evening!</h1>";
break;
case "4":greeting = "<h1>Goood Evening!</h1>";
break;
default:
validInput = false;
} //end switch
if ( validInput == true )
{document.writeln( greeting );}
else
document.write("<h1>Please enter a correct time Knucklehead!</h1>");
// -->
</script>
</head>
<body>
<p> Click refresh or reload to run the script again </p>
</body>
</html>