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 =

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

Roztwór

Adrián élite · Tutor durante 8 años
Weryfikacja ekspertów
4 (286 Votos)

Respuesta

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.

Explicación

## Step 1The 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.## Step 2The 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.## Step 3The fourth line of the code defines a variable 'word', which is the current element in the 'words' array.## Step 4The 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.## Step 5The sixth line of the code logs the 'filteredNords' array to the console.## Step 6The seventh line of the code ends the for loop.## Step 7The eighth line of the code ends the JavaScript code snippet.