Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

JS_Selection

ID: 3864390 • Letter: J

Question

var selection = parseInt(prompt("Enter integer in range 1 to 4")); if (selection < 1 || selection > 4) { alert("Input should be in range of 1 to 4!"); } else { var element_switch = document.getElementById("output_switch"); var element_if = document.getElementById("output_if"); //using switch statements var str1 = "Out put using switch :"; var str2 = "Out put using nested if-else :"; switch (selection) { case 1: str1 += " Athos"; break; case 2: str1 += " Aramis"; break; case 3: str1 += " Porthos"; break; case 4: str1 += " D'Artagnan"; break; } alert(str1); element_switch.innerHTML = str1; //using nested if-else if (selection == 1) { str2 += " Athos"; } else if (selection == 2) { str2 += " Aramis"; } else if (selection == 3) { str2 += " Porthos"; } else if (selection == 4) { str2 += " D'Artagnan"; } alert(str2); element_if.innerHTML = str2; }

Explanation / Answer

85c329b94f5bee83af8678633f0807e0dace2db8d87356b0c5f15bdd33f19e31