forked from wdi-sea-01/js_control_flow
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfilterLongWords.js
More file actions
52 lines (46 loc) · 1.36 KB
/
Copy pathfilterLongWords.js
File metadata and controls
52 lines (46 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// -------------------------------------------------------------------------
// INSTRUCTIONS:
// -------------------------------------------------------------------------
//
// Hardcode an array of words. Have a variable maxLength, push words
// that are less than the maxLength into a new array, and console.log that.
//
// -------------------------------------------------------------------------
var maxLength = 6;
var words = [ "Hardcode",
"an",
"array",
"of",
"words",
"Have",
"a",
"variable",
"maxLength",
"push",
"words",
"that",
"are",
"less",
"than",
"the",
"maxLength",
"into",
"a",
"new",
"array",
"and",
"console",
"log",
"that" ];
var shortWords = [];
for (var i = 0; i < words.length; i++) {
if (words[i].length < maxLength) {
shortWords.push(words[i]);
}
};
console.log('');
console.log('Here is my original array of words:');
console.log(words);
console.log('');
console.log('Here are the words shorter than ' + maxLength + ' characters:');
console.log(shortWords);