-
Notifications
You must be signed in to change notification settings - Fork 61
Nico JS Fundamentals #12
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
base: main
Are you sure you want to change the base?
Changes from all commits
43dad7b
1281099
67989a3
f703ae2
e402620
c08265c
6cd7387
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,18 +2,18 @@ | |
| // than or equal to lower AND less than or equal to upper. | ||
| // Implement this with a single condition. | ||
| function isInRange (num, lower, upper) { | ||
|
|
||
| // TODO: write code in this function body to pass the tests | ||
|
|
||
| if (num >= lower && num <= upper) { | ||
| return true; | ||
| } else { return false } | ||
| } | ||
|
|
||
| // This function should return true if the passed string is equal | ||
| // to "Hello" or "Goodbye". Implement this with a single | ||
| // if statement. | ||
| function isHelloOrGoodbye (val1) { | ||
|
|
||
| // TODO: write code in this function body to pass the tests | ||
|
|
||
| if (val1 === 'Hello' || val1 === 'Goodbye') { | ||
|
Contributor
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. Same as above, the if statement isn't needed here. You can just return |
||
| return true; | ||
| } else { return false } | ||
| } | ||
|
|
||
| // This function should return a string that describes the provided age value. The | ||
|
|
@@ -29,8 +29,11 @@ function isHelloOrGoodbye (val1) { | |
| // 13-19 | Teenager | ||
| // 20+ | Adult | ||
| function getAgeDescription (age) { | ||
|
|
||
| // TODO: write code in this function body to pass the tests | ||
| if (age < 1) { return 'Baby' } | ||
| else if (age >= 1 && age < 5) {return 'Toddler'} | ||
| else if (age >= 5 && age < 13) {return 'Child'} | ||
| else if (age >= 13 && age <= 19) {return 'Teenager'} | ||
| else {return 'Adult'} | ||
| } | ||
|
|
||
| module.exports = { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,23 +2,25 @@ | |
|
|
||
| // This function should return true if there are no elements in the array, false otherwise | ||
| function isArrayEmpty (array) { | ||
|
|
||
| // TODO: write code in this function body to pass the tests | ||
|
|
||
| if (array.length === 0) { | ||
|
Contributor
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. This can also be simplified |
||
| return true | ||
| } else { | ||
| return false | ||
| } | ||
| } | ||
|
|
||
| // This function should return true if num1 is greater than num2, false otherwise | ||
| function isGreaterThan (num1, num2) { | ||
|
|
||
| // TODO: write code in this function body to pass the tests | ||
|
|
||
| if (num1 > num2) { | ||
|
Contributor
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. Same as above :) |
||
| return true | ||
| } else { | ||
| return false | ||
| } | ||
| } | ||
|
|
||
| // This function should return the lowest number in the passed array | ||
| function findLowest (nums) { | ||
|
|
||
| // TODO: write code in this function body to pass the tests | ||
|
|
||
| return Math.min(...nums) | ||
|
Contributor
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. Great use of the Math library, and the array spread syntax! |
||
| } | ||
|
|
||
| module.exports = { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,41 +1,56 @@ | ||
| // This function should return true if the passed string is equal to "Hello" | ||
| function isHello (val1) { | ||
|
|
||
| function isHello(val1) { | ||
| // TODO: write code in this function body to pass the tests | ||
|
|
||
| if (val1 === "Hello") { | ||
|
Contributor
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. This can also be simplified |
||
| return true; | ||
| } else { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| // This function should return true if the passed string is not equal to "Hello" | ||
| function isNotHello (val1) { | ||
|
|
||
| function isNotHello(val1) { | ||
| // TODO: write code in this function body to pass the tests | ||
|
|
||
| if (val1 !== "Hello") { | ||
|
Contributor
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. Same as above :) |
||
| return true; | ||
| } else { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| // This function should return true if the string val1 is is longer | ||
| // than string val2 | ||
| function isLongerThan (val1, val2) { | ||
|
|
||
| function isLongerThan(val1, val2) { | ||
| // TODO: write code in this function body to pass the tests | ||
|
|
||
| if (val1.length > val2.length) { | ||
|
Contributor
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. This can also be simplified |
||
| return true; | ||
| } else { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| // This function should return true if the string passed in the function's first | ||
| // argument has an odd number of vowels | ||
|
|
||
| function hasOddNumberVowels (val1) { | ||
|
|
||
| // TODO: write code in this function body to pass the tests | ||
|
|
||
| const vowels = ["a", "e", "i", "o", "u", "A", "E", "I", "O", "U"]; | ||
|
|
||
| function hasOddNumberVowels(val1) { | ||
| let vowelsCount = 0; | ||
| for (let i = 0; i < val1.length; i++) { | ||
| if (vowels.includes(val1[i])) { vowelsCount++ } | ||
| } | ||
| if (vowelsCount % 2 !== 0) { return true } | ||
| else { return false } | ||
| } | ||
|
|
||
| // this function should return the middle character of a string if it has an odd number | ||
| // of characters. If there are an even number of characters the function should return | ||
| // the middle two letters | ||
|
|
||
| function getMiddleLetter (val1) { | ||
| // TODO: write code in this function body to pass the tests | ||
|
|
||
| function getMiddleLetter(val1) { | ||
| if (val1.length % 2 !== 0) { | ||
| return val1.charAt(val1.length / 2) | ||
| } else { | ||
| return val1.charAt((val1.length / 2) - 1) + val1.charAt(val1.length / 2) | ||
| } | ||
| } | ||
|
|
||
| // This function should return the name of the season for the provided | ||
|
|
@@ -47,9 +62,16 @@ function getMiddleLetter (val1) { | |
| // Summer - June to August | ||
| // Autumn - September to November | ||
| // Winter - December to February | ||
| function seasonForMonth (monthName) { | ||
|
|
||
| // TODO: write code in this function body to pass the tests | ||
| function seasonForMonth(monthName) { | ||
| if (monthName === "March" || monthName === "April" || monthName === "May") { | ||
| return "Spring"; | ||
| } else if (monthName === "June" || monthName === "July" || monthName === "August") { | ||
| return "Summer"; | ||
| } else if (monthName === "September" || monthName === "October" || monthName === "November") { | ||
| return "Autumn"; | ||
| } else if (monthName === "December" || monthName === "January" || monthName === "February") { | ||
| return "Winter"; | ||
| } else { return "" } | ||
| } | ||
|
|
||
| module.exports = { | ||
|
|
@@ -58,5 +80,5 @@ module.exports = { | |
| c: isLongerThan, | ||
| d: hasOddNumberVowels, | ||
| e: getMiddleLetter, | ||
| f: seasonForMonth | ||
| } | ||
| f: seasonForMonth, | ||
| }; | ||
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.
This could be simplified to
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 have learnt about this just this morning, Definitely something I will try to implement in the next exercises