-
-
Notifications
You must be signed in to change notification settings - Fork 258
London class-10 -Junita Lama-JavaScript-1-week 4 #221
base: main
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
|
|
@@ -16,8 +16,11 @@ let names = [ | |
| "Karim", | ||
| "Ahmed", | ||
| ]; | ||
| //function longNameWithA(name) { | ||
| // return name.length > 7; | ||
| //} | ||
|
|
||
| let longNameThatStartsWithA = findLongNameThatStartsWithA(names); | ||
| let longNameThatStartsWithA = names.find(name => name.length > 7); | ||
|
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. You have the right idea here but just need to also add logic for starting with A |
||
|
|
||
| console.log(longNameThatStartsWithA); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,7 +11,11 @@ let pairsByIndex = [[0, 3], [1, 2], [2, 1], null, [3, 0]]; | |
| // If there is a null value in the array exit the program with the error code | ||
| // https://nodejs.org/api/process.html#process_process_exit_code | ||
| // process.exit(1); | ||
|
|
||
| for (let pair of pairsByIndex){ | ||
| if (!pair){ | ||
|
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. I think here it is better to use |
||
| process.exit(1); | ||
| } | ||
| } | ||
| let students = ["Islam", "Lesley", "Harun", "Rukmini"]; | ||
| let mentors = ["Daniel", "Irina", "Mozafar", "Luke"]; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,19 @@ | |
| let students = ["Omar", "Austine", "Dany", "Swathi", "Lesley", "Rukmini"]; | ||
| let group = ["Austine", "Dany", "Swathi", "Daniel"]; | ||
|
|
||
| let groupIsOnlyStudents; // complete this statement | ||
| /*function containsStudent (groupWithStudents){ | ||
| for (let name of groupWithStudents){ | ||
| if(group.includes(students)){ | ||
| return true; | ||
| } else{ | ||
| return false; | ||
| } | ||
|
|
||
| } | ||
|
|
||
| }*/ | ||
|
|
||
| let groupIsOnlyStudents = students.every(name => group.includes(students)? true : false); | ||
|
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. here you don't need the ternary operator |
||
|
|
||
| if (groupIsOnlyStudents) { | ||
| console.log("The group contains only students"); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,25 @@ | |
| */ | ||
|
|
||
| let arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]; | ||
| arr.forEach(n => { | ||
|
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. your logic here is good but I think you should take more care to indent your code more neatly |
||
| if(n % 3 === 0 && n % 5 === 0){ | ||
| console.log("FizzBuzz");} | ||
| else if(n % 3 === 0){ | ||
| console.log("Fizz");} | ||
| else if(n % 5 === 0){ | ||
| console.log("Buzz");} | ||
| else{ | ||
| console.log(n); | ||
| } | ||
|
|
||
|
|
||
|
|
||
| } | ||
| ); | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| /* EXPECTED OUTPUT */ | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,8 +15,8 @@ let everyone = [ | |
| "Swathi", | ||
| ]; | ||
|
|
||
| let firstFive; // complete this statement | ||
| let lastFive; // complete this statement | ||
| let firstFive = everyone.slice(0, 5); // complete this statement | ||
| let lastFive = everyone.slice(2, 7); // complete this statement | ||
|
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. here you can use negative number indexes with |
||
|
|
||
| /* | ||
| DO NOT EDIT BELOW THIS LINE | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,11 +14,11 @@ let names = [ | |
| "Arron Graham", | ||
| ]; | ||
|
|
||
| names[0] = names[0].substring(); | ||
| names[1] = names[1].substring(); | ||
| names[2] = names[2].substring(); | ||
| names[3] = names[3].substring(); | ||
| names[4] = names[4].substring(); | ||
| names[0] = names[0].substring(0,6); | ||
| names[1] = names[1].substring(0,7); | ||
| names[2] = names[2].substring(0,4); | ||
| names[3] = names[3].substring(0,4); | ||
| names[4] = names[4].substring(0,5); | ||
|
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. you could also do e.g. |
||
|
|
||
| names.forEach((name) => { | ||
| console.log(name); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,10 +6,7 @@ | |
| HINT: You will need to use .substring() twice | ||
| */ | ||
|
|
||
| let statement = "I do not like programming"; | ||
|
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. you could also use |
||
|
|
||
| let result = ""; | ||
|
|
||
| let statement = "I do not like programming" | ||
| console.log(result); | ||
|
|
||
| /* EXPECTED OUTPUT | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,7 +11,17 @@ | |
| Some string methods that might help you here are .replace() and .substring(). | ||
| */ | ||
|
|
||
| function findSafeOxygenLevel() {} | ||
| function findSafeOxygenLevel(oxygenLevels) { | ||
| let planets=oxygenLevels.filter(oxygenLevel =>oxygenLevel.includes("%")) | ||
| let numberLevels= planets.map(number => parseFloat(number)) | ||
|
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. I would like better indentation here 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. here you could chain together the array methods without having to declare variables with |
||
| let safePlanets=numberLevels.find(level => level> 19.5 && level<23.5) | ||
| if(safePlanets!==undefined){ | ||
| return `${safePlanets}%`; | ||
| } | ||
|
|
||
| } | ||
|
|
||
|
|
||
|
|
||
| /* ======= TESTS - DO NOT MODIFY ===== */ | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,7 +7,10 @@ | |
| - Returns an array containing only the names of the who have attended AT LEAST 8 classes | ||
| */ | ||
|
|
||
| function getEligibleStudents() {} | ||
| function getEligibleStudents(students, attendance) { | ||
| let studentName = students.filter(attendance=>attendance[1]>=8) | ||
| return studentName.map(names=>names[0]); | ||
|
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. here you could chain together filter and map with the extra |
||
| } | ||
|
|
||
| /* ======= TESTS - DO NOT MODIFY ===== */ | ||
|
|
||
|
|
||
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.
For this exercise you should define your own function
findLongNameThatStartsWithAand implement your logic there.