Microsoft
98-382 · Question #1
You need to write a loop that will traverse the length of an array to find the value orange. If an array element value is null, the code should immediately go to the next element. When the value is…
Box 1: for Box 2: continue Box 3: break
Control Flow with Decisions and Loops
Question
You need to write a loop that will traverse the length of an array to find the value orange. If an array element value is null, the code should immediately go to the next element. When the value is found, the loop should exit. How should you complete the code? To answer, drag appropriate keywords to the correct locations. Each keyword may be used once, more than once, or not at all. You may need to drag the split bar between panes or scroll to view content.
Keywords:
for, break, continue, while, do
Complete the following code snippet:
<!DOCTYPE html>
<html>
<head>
<script>
function doWork() {
var list = ["apple", "pear", null, "orange", "banana"];
// Box 1
(var i = 0; i < list.length; ++i) {
if(list[i] == null) {
// Box 2
}
if(list[i] == "orange") {
alert("found");
// Box 3
}
}
console.log(list[i]);
}
</script>
</head>
<body>
<input type="button" value="test" onclick="doWork()" />
</body>
</html>
Explanation
Box 1: for Box 2: continue Box 3: break
Topics
#for loop#break#continue#array traversal
Community Discussion
No community discussion yet for this question.