Mickey Haile JavaScript-Core-1-Coursework-Week3 - #169
Conversation
JDysiewicz
left a comment
There was a problem hiding this comment.
There were a couple logic errors, but usually this is things like off-by-one errors which are easy to make. Overall it's looking pretty good :P
| let hello = sayHello(); | ||
| console.log(hello); | ||
|
|
||
| /* hello is a variable not a function */ |
There was a problem hiding this comment.
In javascript, functions can be assigned to variables e.g.
const hello = sayHello
hello()
So the reason that it is undefined is because you assign hello to the result of calling sayHello(); as sayHello() doesn't return anything, hello is undefined.
|
|
||
| sayHelloToUser(); | ||
|
|
||
| /*needs a parameter*/ |
There was a problem hiding this comment.
technically, it's an argument (parameter is user, argument is the value assigned to user when invoking a function)
| while (i < 2 * n){ | ||
| even.push(i);} | ||
| i += 2 |
There was a problem hiding this comment.
Think your syntax is off here; you're incrementing i after the while loop is done.
Also, for checking even numbers, the modulo % operator is what you're looking for.
|
|
||
| // TODO - Write for loop code here | ||
|
|
||
| for (let i=0;i<WRITERS.length-1;i++){ |
There was a problem hiding this comment.
as you're starting from 0 and just using a < instead of <=, you just need to check if i<WRITERS.length instead of .length-1
| // TODO | ||
| let newArr = []; | ||
| for (let title of allArticleTitles) { | ||
| if (title.length < 65) newArr.push(title); |
There was a problem hiding this comment.
Just to keep things readable, I'd advise always using {} with if statements even if they're 1 line:
if(title.length < 65) {
newArr.push(title)
}
| // TODO | ||
| for (var i = 0; i < allArticleTitles.length; i++) { | ||
| // Last i elements are already in place | ||
| for (var j = 0; j < allArticleTitles.length - i - 1; j++) { |
There was a problem hiding this comment.
similar to above, you don't need to -1 here
| // TODO | ||
| let newArr = []; | ||
| for (let title of allArticleTitles) { | ||
| if (/[0-9]/.test(title) === true) { |
There was a problem hiding this comment.
you could simplify this a little with a shorthand character class in regex /\d/.test)
| sum += title.length; | ||
| } | ||
|
|
||
| return Math.round(sum / allArticleTitles.length); |
There was a problem hiding this comment.
what if articleTitle.length is 0?
No description provided.