-
-
Notifications
You must be signed in to change notification settings - Fork 279
NW5-Ahmed_Mahmoud-JavaScript-Core-1-Coursework-Week3 #137
base: main
Are you sure you want to change the base?
Changes from all commits
7495a44
6714449
da7a8c0
db8d14e
a0fb104
aed0d37
b975801
630a857
43fab1f
82925ee
cdbf797
c1f32ff
5d327b7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,7 +8,18 @@ | |
|
|
||
| function evenNumbersSum(n) { | ||
| // TODO | ||
| } | ||
| const ourArray = []; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hey Danti, I can see the approach your going for here, but it looks like you forgot to include some code - this file doesn't run and references a missing function |
||
| let i = 0; | ||
|
|
||
| do { | ||
| ourArray.push(i); | ||
| i++; | ||
| } while (i < 10); | ||
| return i; | ||
| } | ||
|
|
||
| console.log(sumEvens(ourArray)); | ||
|
|
||
|
|
||
| console.log(evenNumbersSum(3)); // should output 6 | ||
| console.log(evenNumbersSum(0)); // should output 0 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,13 @@ function generateRandomNumber() { | |
|
|
||
| function getRandomNumberGreaterThan50() { | ||
| // TODO - implement using a do-while loop | ||
| let generatedNumber; | ||
|
|
||
| do { | ||
| generatedNumber = generateRandomNumber(); | ||
| } while(generatedNumber <= 50); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The exercie says number greater than 50 not greater than or equal so please try to stick in with reqirements. I know as small issue but it will help you to stick to exact instructions, you do |
||
|
|
||
| return generatedNumber; | ||
| } | ||
|
|
||
| /* ======= TESTS - DO NOT MODIFY ===== */ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,15 @@ | |
| */ | ||
| function potentialHeadlines(allArticleTitles) { | ||
| // TODO | ||
| let headlines = []; | ||
|
|
||
| for(let title of allArticleTitles) { | ||
| if(title.length <= 65) { | ||
| headlines.push(title); | ||
| } | ||
| } | ||
|
|
||
| return headlines; | ||
| } | ||
|
|
||
| /* | ||
|
|
@@ -15,6 +24,22 @@ function potentialHeadlines(allArticleTitles) { | |
| */ | ||
| function titleWithFewestWords(allArticleTitles) { | ||
| // TODO | ||
| let fewestWordsSoFar; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Always a good idea to assign the number var to 0 to avoid random number being put into the variable by the js compiler |
||
| let titleWithFewestWords; | ||
|
|
||
| for(let title of allArticleTitles) { | ||
|
|
||
| // working out the number of words in the title by splitting on the space character | ||
| // this will generate an array. Read more: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split | ||
| let numWords = title.split(' ').length; | ||
|
|
||
| if(fewestWordsSoFar === undefined || numWords < fewestWordsSoFar) { | ||
| fewestWordsSoFar = numWords; | ||
| titleWithFewestWords = title; | ||
| } | ||
| } | ||
|
|
||
| return titleWithFewestWords; | ||
| } | ||
|
|
||
| /* | ||
|
|
@@ -24,6 +49,27 @@ function titleWithFewestWords(allArticleTitles) { | |
| */ | ||
| function headlinesWithNumbers(allArticleTitles) { | ||
| // TODO | ||
| let articlesWithNumbers = []; | ||
|
|
||
| for(let title of allArticleTitles) { | ||
| // Making use of the new function created below | ||
| if(doesTitleContainANumber(title)) { | ||
| articlesWithNumbers.push(title); | ||
| } | ||
| } | ||
|
|
||
| return articlesWithNumbers; | ||
| } | ||
|
|
||
| // Creating another function to help break this problem down into smaller parts | ||
| function doesTitleContainANumber(title) { | ||
| for(let character of title) { | ||
| if(character >= '0' && character <= '9') { | ||
| return true; | ||
| } | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| /* | ||
|
|
@@ -32,6 +78,13 @@ function headlinesWithNumbers(allArticleTitles) { | |
| */ | ||
| function averageNumberOfCharacters(allArticleTitles) { | ||
| // TODO | ||
| let totalCharacters = 0; | ||
|
|
||
| for(let title of allArticleTitles) { | ||
| totalCharacters += title.length; | ||
| } | ||
|
|
||
| return Math.round(totalCharacters / allArticleTitles.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.
I think you mean similar to me, //in this example we don't have arr[3], because we just have [0],[1].[2]and we don't have it.