Pagina de inicio
/
Tecnología
/
11. var words = ['apple"","Bug","car","dream","ear""food"]; var filteredNords = [1; for (vari i 0; 1 < words.length;i++) ( var word = words(1); if (word.length 4) appendItem(filterediords,word); ) ) console.log(filteredwords); If the program above is run, what will be displayed in the console? A. [apple, dream] B. [bug, car, ear] C. Lbug, car, ean food] D. [apple, dream, food

Problemas

11.
var words = ['apple"","Bug","car","dream","ear""food"];
var filteredNords = [1;
for (vari i 0; 1 < words.length;i++) (
var word = words(1);
if (word.length 4)
appendItem(filterediords,word);
)
)
console.log(filteredwords);
If the program above is run, what will be displayed in the console?
A. [apple, dream]
B. [bug, car, ear]
C. Lbug, car, ean food]
D. [apple, dream, food

11. var words = ['apple"","Bug","car","dream","ear""food"]; var filteredNords = [1; for (vari i 0; 1 < words.length;i++) ( var word = words(1); if (word.length 4) appendItem(filterediords,word); ) ) console.log(filteredwords); If the program above is run, what will be displayed in the console? A. [apple, dream] B. [bug, car, ear] C. Lbug, car, ean food] D. [apple, dream, food

Solución

avatar
Adriánélite · Tutor durante 8 años
expert verifiedVerificación de expertos
4.0 (286 votos)

Responder

The correct answer is A. [apple, dream]. The 'filteredNords' array will contain only the words 'apple' and 'dream', as they are the only words in the 'words' array that have a length greater than 4. The words 'Bug', 'car', 'ear', and 'food' are not added to the 'filteredNords' array because their lengths are not greater than 4.

Explicar

## Step 1<br />The given program is a JavaScript code snippet. The first line of the code defines an array called 'words', which contains five elements: 'apple', 'Bug', 'car', 'dream', and 'ear'. The second line of the code defines another array called 'filteredNords', which is initially empty.<br /><br />## Step 2<br />The third line of the code starts a for loop, which will iterate through each element in the 'words' array. The loop starts with 'i' equal to 0, and continues until 'i' is less than the length of the 'words' array.<br /><br />## Step 3<br />The fourth line of the code defines a variable 'word', which is the current element in the 'words' array.<br /><br />## Step 4<br />The fifth line of the code checks if the length of the 'word' is greater than 4. If it is, the 'word' is added to the 'filteredNords' array.<br /><br />## Step 5<br />The sixth line of the code logs the 'filteredNords' array to the console.<br /><br />## Step 6<br />The seventh line of the code ends the for loop.<br /><br />## Step 7<br />The eighth line of the code ends the JavaScript code snippet.
Haz clic para calificar: