Skip to content

Conversation

@mattcam3r0n
Copy link
Owner

class 1 project

Copy link

@reneemeyer reneemeyer left a 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();

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

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?

Copy link
Owner Author

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';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice check!


// 6. Write a JavaScript program that runs only when 2 things are true.
function numberIsBetween1And100(num) {
return num >= 1 && num <= 100; // inclusive

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){....}


// 7. Write a JavaScript program that runs when 1 of 2 things are true.
function isZeroOrNegative(num) {
return num === 0 || num < 0;

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.


// 8. Write a JavaScript program that runs when both things are not true.
function isNotZeroOrNegative(num) {
return !(num === 0 || num < 0);

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.

Copy link

@reneemeyer reneemeyer left a 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants