Conversation
reneemeyer
left a comment
There was a problem hiding this comment.
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(); |
|
|
||
| // 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.
what would you do if num isn't a number?
There was a problem hiding this comment.
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'; |
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.
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.
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.
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.
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