-
-
Notifications
You must be signed in to change notification settings - Fork 301
West Midlands | Alireza Seifi Shalamzari | Module-Structuring-and-Testing-Data:Sprint1 exercise | Week 1 #161
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
Conversation
cjyuan
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.
I have left my comment in the code.
Why not try also
- Explain and fix the errors in the files in folder
errors? - Interpret code in the files in folder
interpret - Answer questions in the file in folder
explore
| // Create a variable called decimalPart and assign to it an expression that evaluates to 0.5678 ( the decimal part of num ) | ||
| // Create a variable called roundedNum and assign to it an expression that evaluates to 57 ( num rounded to the nearest whole number ) | ||
| wholeNumberPart = Math.floor(num); // Create a variable called wholeNumberPart and assign to it an expression that evaluates to 56 ( the whole number part of num ) | ||
| decimalPart = +(num % 1).toFixed(10);// Create a variable called decimalPart and assign to it an expression that evaluates to 0.5678 ( the decimal part of num ) |
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 is the use of the prefix +? Is it necessary?
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.
If you look at line 6, the ".tofix(10)" will get the number, separates the decimal part and return it. But the returned decimal is now a float, it is an String. The "+" used as prefix will make sure that when the result is going to be assigned to "decimalPart" variable, is actually a number not string.
In our case it is not necessary since we only need the decimal part to be returned but if we had another operation to do on variable, it is important for mathematical part to be a number not string.
| let middleName = "Katherine"; | ||
| let lastName = "Johnson"; | ||
|
|
||
| initials = [firstName[0], middleName[0], lastName[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 would create an array ["C", "K", "J"] instead of producing a string "CKJ".
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 am sure in my final code when I tested it, it retuerned CKJ. there is a chance I forgot to actually push the last line commit which will print the "initials" members together.
No description provided.