-
Notifications
You must be signed in to change notification settings - Fork 6.7k
BCN - Desiree Lucas Cristian #151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Key points:
- If the function needs to return something, RETURN it.
- DRY, Don't Repeat Yourself. Reuse your functions when possible.
That said, good job. Keep up the hard work. 👍
console.log ("second"); | ||
} | ||
else { | ||
console.log("the numbers are the same"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are showing the result in the console instead of returning it. That way, the variable 'largest' in line 14 is going to be undefined (because you are not returning anything). Usually you want your functions to return something, that way you can use that value ahead.
biggest=words[ix]; | ||
} | ||
} | ||
for ( var j=0; j<words.lenght; j++){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need this second for. I understand you use it to display more than one result (if there is a tie for the longest word), but the problem again is that you MUST return the result instead of showing it in the console. In this case, if you want to display more than one word, you will need an array. If the function's signature is expecting an output of a value, returning an array could be a problem.
|
||
var totalSum=0; | ||
array.forEach(function(number){ | ||
totalSum+=number; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job with the forEach. However, you have forgotten return something.
@@ -34,7 +58,11 @@ console.log(total); | ||
|
||
// Calculate the Average | ||
function averageNumbers (array) { | ||
|
||
var totalSum=0; | ||
array.forEach(function(number){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have another function that sums all the values in an array? Then, maybe you can use it here instead of repeating code.
@@ -43,9 +71,14 @@ console.log(average); | ||
|
||
// Array of Strings | ||
function averageWordLength (array) { | ||
|
||
var total=0; | ||
array.forEach(function(number){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job. However, be careful with variable's names. Don't call it number if it is a word.
|
||
var biggest=""; | ||
for ( var ix=0; ix < words.length; ix++){ | ||
if ( biggest.length < words[ix].length){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't want to find the biggest word, you want to check if that word is in the array.
@@ -0,0 +1,22 @@ | ||
<script> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is this? Why are you including a script in another html file?
@gominolas
@lacazeto