-
Notifications
You must be signed in to change notification settings - Fork 0
datatypes.js - added sumOfTwoNumbers #1
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: gh-pages
Are you sure you want to change the base?
Conversation
reneemeyer
left a comment
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.
Matt, nice job on the methods. However I need you to really look at the last three problems. Take these problems extremely literally. The problems say nothing about evaluating numbers. Make sure when you read your function in english it matches exactly what the problem says. Also, we did the "both are true" problem in class. The other two should follow the same format.
|
|
||
| // 1. Write a JavaScript program to display the current day and time. | ||
| function displayDateAndTime() { | ||
| return Date(); |
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.
nice simple return!
|
|
||
| // 2. Write a JavaScript program to convert a number to a string. | ||
| function convertNumberToString(num) { | ||
| // ensure num is really a number, to handle strings, nulls, etc |
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 would you do if num isn't a 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.
The requirement reads "convert a number to a string" and does not define how exceptional cases should be handled, so I chose to handle arguments that are "not a number" by returning the string 'NaN'. This is accomplished by first casting the incoming value using Number(). Invalid values, such as null, undefined, objects, etc, will produce NaN, which then becomes 'NaN' when toString() is called.
| function getDataType(val) { | ||
| // NaN and null are special cases | ||
| if (Number.isNaN(val)) return 'NaN'; | ||
| if (val === null) return 'null'; |
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.
nice check!
01week/datatypes.js
Outdated
|
|
||
| // 6. Write a JavaScript program that runs only when 2 things are true. | ||
| function numberIsBetween1And100(num) { | ||
| return num >= 1 && num <= 100; // inclusive |
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 function evaluates if a number is greater or equal to one and if it's less than or equal to 100. I need a function that accepts two arguments and runs if both arguments evaluate to true. We did this problem in class. if(arg1 && arg2){....}
01week/datatypes.js
Outdated
|
|
||
| // 7. Write a JavaScript program that runs when 1 of 2 things are true. | ||
| function isZeroOrNegative(num) { | ||
| return num === 0 || num < 0; |
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 function evaluates if a number is equal to zero or if it's less than 0. I need a function that accepts two arguments and runs if one of the arguments evaluates to true.
01week/datatypes.js
Outdated
|
|
||
| // 8. Write a JavaScript program that runs when both things are not true. | ||
| function isNotZeroOrNegative(num) { | ||
| return !(num === 0 || num < 0); |
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 function evaluates if a number not is equal to zero or if it's less than 0.
I need a function that accepts two arguments and runs if neither of the arguments evaluates to true.
reneemeyer
left a comment
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.
Nice job, go ahead and merge and delete the branch.Then in your terminal, go to your gh-pages and do a git pull
class 1 project