In: Computer Science
Write a switch statement that uses the colour of a swab sample of COVID testing vehicle to send a message to a local doctor. Use the messages given for each colour in the table below. Justify your answer.
Colour |
Message |
Blue |
“No virus” |
Yellow |
“Needs to be under observation” |
Red |
“Needs to be admitted in COVID ward” |
Hi,
I am done this with the Javascript. You can find out the below code and you can use the swith logic in any language. Just need to modify the Control which need to modify.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<script src="https://code.jquery.com/jquery-1.9.1.min.js"></script>
<script>
$(document).ready(function () {
//This function will execute when HTML dom elements loaded in the Browser
var btn = $("#btnSendMessage").off("click").on("click", function () {
//Button Click Events
CallSwitchStatement();
})
//This function will execute when HTML dom elements loaded in the Browser
var btn = $("#btnClearMessage").off("click").on("click", function () {
//Button Click Events
//Clear the Text Value
$("#txtColor").val("");
//Call the switch statement
CallSwitchStatement();
})
//Switch Statement
function CallSwitchStatement() {
//Get the Messate which need to send
//we have set message in lower cases and accordingly we have set it to the switch statement
var Message = $("#txtColor").val().trim().toLowerCase();
//Switch statement on Message
switch (Message) {
//No Virus Case
case "no virus":
$($("#txtColor")[0]).css("color", "blue");
break;
//needs to be under observation Case
case "needs to be under observation":
$($("#txtColor")[0]).css("color", "Yellow");
break;
//needs to be admitted in covid ward Case
case "needs to be admitted in covid ward":
$($("#txtColor")[0]).css("color", "Red");
break;
//Default Case
default:
$($("#txtColor")[0]).css("color", "Black");
}
}
});
</script>
</head>
<body>
<input type="text" id="txtColor" style="width:400px;height:20px" />
<input type="button" id="btnSendMessage" value="Check Message Color" style="width:200px;height:20px" />
<input type="button" id="btnClearMessage" value="Clear Message Color" style="width:200px;height:20px" />
</body>
</html>
Output:
When this HTML loaded in browser and when you entered the cases as below
1) No Virus/no virus/No virus
Chech result after Click the button - Check Message Color
Chech result after Click the button - Clear Message Color
2) Needs to be under Observation/needs to be under observation
Chech result after Click the button - Check Message Color
Chech result after Click the button - Clear Message Color
2) Needs to be admitted in COVID ward/needs to be admitted in covid ward
Chech result after Click the button - Check Message Color
Chech result after Click the button - Clear Message Color