PrepAway - Latest Free Exam Questions & Answers

Which of the following demonstrate the correct syntax for the switch statement?

Which of the following demonstrate the correct syntax for the switch statement?

PrepAway - Latest Free Exam Questions & Answers

A.
var myName= “Paul”
switch (myName){
case “Peter”
document.write(“My name is Peter.
“)
break
case “Paul”
document.write(“My name is Paul.
“)
break: (default);
document.write(“I do not have a name.
“)
}

B.
var myName= “Paul”
switch (myName){
case “Peter”
document.write(“My name is Peter.
“)
break
case “Paul”
document.write(“My name is Paul.
“)
break: (default);
document.write(“I do not have a name.
“)
}

C.
var myName= “Paul”
switch (myName){
case (Peter)
document.write(“My name is Peter.
“)
break
case (Paul)
document.write(“My name is Paul.
“)
break;
case: (default);
document.write(“I do not have a name.
“)
}

D.
var myName= “Paul”
switch (myName){
case (Peter)
document.write(“My name is Peter.
“)
break
case (Paul)
document.write(“My name is Paul.
“)
break;
case: (default);
document.write(“I do not have a name.
“)
}

Explanation:

2 Comments on “Which of the following demonstrate the correct syntax for the switch statement?

  1. Joshua says:

    These all have horrible syntax…First off, you need a semicolon after every break. Second, you should have colons after each case, including the default, which is not in parenthesis.
    Please fix this.




    1



    0

Leave a Reply