diff --git a/curriculum/challenges/english/25-front-end-development/quiz-javascript-loops/66edcd49e73385dd4df54ac7.md b/curriculum/challenges/english/25-front-end-development/quiz-javascript-loops/66edcd49e73385dd4df54ac7.md index 944144a8574..73fa8e58bf9 100644 --- a/curriculum/challenges/english/25-front-end-development/quiz-javascript-loops/66edcd49e73385dd4df54ac7.md +++ b/curriculum/challenges/english/25-front-end-development/quiz-javascript-loops/66edcd49e73385dd4df54ac7.md @@ -17,439 +17,518 @@ Answer all of the questions below correctly to pass the quiz. #### --text-- -Placeholder question +Which of the following best describes iteration? #### --distractors-- -Placeholder distractor 1 +It is the process of writing code repeatedly until it works correctly. --- -Placeholder distractor 2 +It is a technique for storing data in consecutive memory locations. --- -Placeholder distractor 3 +It is the process of sending signals between components to establish a connection. #### --answer-- -Placeholder answer +It is the process of repeating a set of instructions multiple times until a condition is met. ### --question-- #### --text-- -Placeholder question +What technique is used for iterations in programming? #### --distractors-- -Placeholder distractor 1 +Recursion --- -Placeholder distractor 2 +Conditionals --- -Placeholder distractor 3 +Compilation #### --answer-- -Placeholder answer +Looping ### --question-- #### --text-- -Placeholder question +Which of the following is not an iterable object? #### --distractors-- -Placeholder distractor 1 +Map --- -Placeholder distractor 2 +String --- -Placeholder distractor 3 +Array #### --answer-- -Placeholder answer +Math object ### --question-- #### --text-- -Placeholder question +Which of the following is not a type of loop supported in JavaScript? #### --distractors-- -Placeholder distractor 1 +`for` loop --- -Placeholder distractor 2 +`while` loop --- -Placeholder distractor 3 +`for...in` loop #### --answer-- -Placeholder answer +`if...else` loop ### --question-- #### --text-- -Placeholder question +What is the correct order of the `for` loop declaration? #### --distractors-- -Placeholder distractor 1 +```javascript +for (condition; increment/decrement; initialization) + statement; +``` --- -Placeholder distractor 2 +```javascript +for (increment/decrement; condition; initialization) + statement; +``` --- -Placeholder distractor 3 +```javascript +for (initialization; increment/decrement; condition) + statement; +``` #### --answer-- -Placeholder answer +```javascript +for (initialization; condition; increment/decrement) + statement; +``` ### --question-- #### --text-- -Placeholder question +Which loop executes the code block once, before checking if the condition is true, and will continue working as long as the condition remains true? #### --distractors-- -Placeholder distractor 1 +`while` loop --- -Placeholder distractor 2 +`for...of` loop --- -Placeholder distractor 3 +`for...in` loop #### --answer-- -Placeholder answer +`do...while` loop ### --question-- #### --text-- -Placeholder question +Which loop loops over the values of an iterable object? #### --distractors-- -Placeholder distractor 1 +`for...in` loop --- -Placeholder distractor 2 +`for` loop --- -Placeholder distractor 3 +`do...while` loop #### --answer-- -Placeholder answer +`for...of` loop ### --question-- #### --text-- -Placeholder question +Which of the following best defines an infinite loop? #### --distractors-- -Placeholder distractor 1 +A loop that runs until the condition becomes false. --- -Placeholder distractor 2 +A loop that runs once and then is terminated. --- -Placeholder distractor 3 +A loop that automatically stops after a fixed number of iterations. #### --answer-- -Placeholder answer +A loop that continues to run indefinitely because the termination condition is never met or is absent. ### --question-- #### --text-- -Placeholder question +For iterating over an array, which loop is not the best? #### --distractors-- -Placeholder distractor 1 +`for` loop --- -Placeholder distractor 2 +`for...of` loop --- -Placeholder distractor 3 +`for...in` loop #### --answer-- -Placeholder answer +`while` loop ### --question-- #### --text-- -Placeholder question +Which loop is the best for iterating objects? #### --distractors-- -Placeholder distractor 1 +`for...of` loop --- -Placeholder distractor 2 +`do...while` loop --- -Placeholder distractor 3 +`for` loop #### --answer-- -Placeholder answer +`for...in` loop ### --question-- #### --text-- -Placeholder question +What is the difference between the `for...in` loop and the `for...of` loop? #### --distractors-- -Placeholder distractor 1 +`for...in` loop iterates over property values, while the `for...of` loop iterates over property names (keys). --- -Placeholder distractor 2 +`for...in` loops create new properties, while `for...of` loops modify existing properties. --- -Placeholder distractor 3 +`for...in` loops can only be used with strings, while the `for...of` loops can be used with both strings and numbers. #### --answer-- -Placeholder answer +`for...in` loop iterates over property names (keys), while the `for...of` loop iterates over property values. ### --question-- #### --text-- -Placeholder question +To prevent an infinite loop from occurring, all but one of these are expected to be part of the loop used. #### --distractors-- -Placeholder distractor 1 +Initialization of variable. --- -Placeholder distractor 2 +A loop condition that eventually gives false. --- -Placeholder distractor 3 +Increment/decrement logic. #### --answer-- -Placeholder answer +A loop condition that always returns true. ### --question-- #### --text-- -Placeholder question +What statement can be used to break out of a loop completely? #### --distractors-- -Placeholder distractor 1 +The `continue` statement --- -Placeholder distractor 2 +The `label` statement --- -Placeholder distractor 3 +The `skip` statement #### --answer-- -Placeholder answer +The `break` statement ### --question-- #### --text-- -Placeholder question +Which statement can be used to skip the current iteration and move to the next iteration? #### --distractors-- -Placeholder distractor 1 +The `break` statement --- -Placeholder distractor 2 +The `label` statement --- -Placeholder distractor 3 +The `return` statement #### --answer-- -Placeholder answer +The `continue` statement ### --question-- #### --text-- -Placeholder question +It is generally recommended to avoid using the `for...in` loop in JavaScript. What is the reason for that? #### --distractors-- -Placeholder distractor 1 +It only works with arrays and not with objects. --- -Placeholder distractor 2 +It is the best way to iterate over large objects. --- -Placeholder distractor 3 +It guarantees the order of property enumeration. #### --answer-- -Placeholder answer +It could enumerate over inherited properties of an object. ### --question-- #### --text-- -Placeholder question +What will be the output of the code below? + +```javascript +for (let i = 1; i < 6; i++) { + if (i === 4) break; + console.log(i); +} +``` #### --distractors-- -Placeholder distractor 1 +```javascript +1,2,3,4,5,6 +``` --- -Placeholder distractor 2 +```javascript +1,2,3,4,5 +``` --- -Placeholder distractor 3 +```javascript +1,2,3,4 +``` #### --answer-- -Placeholder answer +```javascript +1,2,3 +``` ### --question-- #### --text-- -Placeholder question +What will be the output of the code below? + +```javascript +const shoppingList = { tomatoes: 4, apples: 10 }; +for (const item in shoppingList) { + console.log(item); +} +``` #### --distractors-- -Placeholder distractor 1 +```javascript +tomatoes - 4, apples - 10 +``` --- -Placeholder distractor 2 +```javascript +4, 10 +``` --- -Placeholder distractor 3 +```javascript +tomatoes:4, apples:10 +``` #### --answer-- -Placeholder answer +```javascript +tomatoes, apples +``` ### --question-- #### --text-- -Placeholder question +What will be the output of the code below? + +```javascript +for (let i = 2; i <= 13; i++) { + if (i % 2 === 0) continue; + console.log(i); +} +``` #### --distractors-- -Placeholder distractor 1 +```javascript +2,4,6,8,10,12 +``` --- -Placeholder distractor 2 +```javascript +1,3,5,7,9,11,13 +``` --- -Placeholder distractor 3 +```javascript +1,3,5,7,9,11 +``` #### --answer-- -Placeholder answer +```javascript +3,5,7,9,11,13 +``` ### --question-- #### --text-- -Placeholder question +What would be the output of the code below? + +```javascript +const fruits = ["Mango", "Pineapple", "Oranges"]; +for (const fruit in fruits) { + console.log(fruit); +} +``` #### --distractors-- -Placeholder distractor 1 +```javascript +Mango, Pineapple +``` --- -Placeholder distractor 2 +```javascript +Pineapple, Oranges, Mango +``` --- -Placeholder distractor 3 +```javascript +Oranges, Pineapple, Mango +``` #### --answer-- -Placeholder answer +```javascript +Mango, Pineapple, Oranges +``` ### --question-- #### --text-- -Placeholder question +How many times will the code below output the string `in the loop`? + +```javascript +let x = 0 +while (x < 5) { + console.log("in the loop"); +} +``` #### --distractors-- -Placeholder distractor 1 +3 times. --- -Placeholder distractor 2 +4 times. --- -Placeholder distractor 3 +5 times. #### --answer-- -Placeholder answer +Infinite.