Microsoft
98-382 · Question #28
The ABC company offers a mid-week discount of 10% on Wednesdays. You need to write a JavaScript function that meets the following requirements: -> Accepts the day of the week as a string -> Returns…
``javascript 01 function getDiscount(day) { 02 var discount = 0; 03 switch (day) { 04 case "Wednesday": 05 discount = .1; 06 break; 07 default: 08 discount = 0; 09 break; 10 } 11 return discount; 12 } ``
Implementing Flow Control
Question
The ABC company offers a mid-week discount of 10% on Wednesdays.
You need to write a JavaScript function that meets the following requirements:
-> Accepts the day of the week as a string
-> Returns the appropriate discount
You create the following code. Line numbers are included for reference only.
01 function getDiscount(day) {
02 var discount = 0;
03
04
05 discount = .1;
06 break;
07
08 discount = 0;
09 break;
10 }
11 return discount;
12 }
You must complete the code at lines 03, 04, and 07. How should you complete the code? To answer, select the appropriate code segments in the answer area. NOTE: Each correct selection is worth one point.Explanation
01 function getDiscount(day) {
02 var discount = 0;
03 switch (day) {
04 case "Wednesday":
05 discount = .1;
06 break;
07 default:
08 discount = 0;
09 break;
10 }
11 return discount;
12 }
Topics
#switch statement#functions#break statement#discount logic
Community Discussion
No community discussion yet for this question.