Question: <!DOCTYPE html> <html> <head> <title>Q1</title> </head> <body> <script
ID: 3548672 • Letter: Q
Question
Question:
<!DOCTYPE html>
<html>
<head>
<title>Q1</title>
</head>
<body>
<script type="text/script">
var name;
var price;
var total_earning;
var code=prompt("Script Prompt:Your Material :M1:Newspaper M2:Tin Cars M3:Plastic bottles");
switch (code)
{
Case "M1":
name="Newspaper";
price=0.30;
break;
Case "M2":
name="Tin cans";
price=1.30;
break;
Case "M3":
name="Plastic bottles";
price=0.50;
break;
default:
name="";
price=0;
break;
}
var Weight=parseFloat(prompt("Script Prompt:<br/><br/>How many kilograms?:"));
total_earning=price*Weight;
alert("Items: "+name+"<br/>Weight: "+Weight+"kg"+"<br/>Rate: RM"+price+"<br/>You earn: RM"+total_earning);
</script>
</body>
</html>
please my code and correct my error using comment.
Thank.
Explanation / Answer
/* The only problem in your code was that the "C" in "case" was capitalised. in switch case, case must be written as "case" and not "Case"
Let me know if you have doubts
*/
<!DOCTYPE html>
<html>
<head>
<title>Q1</title>
</head>
<body>
<script type="text/script">
var name;
var price;
var total_earning;
var code=prompt("Script Prompt:Your Material :M1:Newspaper M2:Tin Cars M3:Plastic bottles");
switch(code)
{
case "M1":
name="Newspaper";
price=0.30;
break;
case "M2":
name="Tin cans";
price=1.30;
break;
case "M3":
name="Plastic bottles";
price=0.50;
break;
default:
name="";
price=0;
break;
}
var Weight=parseFloat(prompt("Script Prompt:<br/><br/>How many kilograms?:"));
total_earning=price*Weight;
alert("Items: "+name+"<br/>Weight: "+Weight+"kg"+"<br/>Rate: RM"+price+"<br/>You earn: RM"+total_earning);
</script>
</body>
</html>
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.