Javascript: 101 Week 1 Track 2
This post is a reply for the Javascript: 101 Week 1 Track 2.
Mainly answering questions for reflection and homework.
Reflection
- Type is a way to represent the data in computer memory. It is useful in writing programs as it can be keep in the way as we want efficiently.
- We lose precision when performing operations with decimal numbers in JavaScript because of the limitation of number representation in computer memory. It can be a problem when we are dealing money by dividing with odd number, such as 3.
- The following operation produces the given result 115 * 4 - 4 + 88 / 2 = 500 as multiplication and division are calculating first before addition and subtraction. After multiplication and division, the equation will be 460 - 4 + 44.
- A backslash character in a String is to indicate the next character is special, escape character.
- The purpose of typeof 4.5 is to returning the type of 4.5 in string format, which is number in this case. On the other hand, typeof (typeof 4.5) will return string because typeof function is returning string type. There is not special type of data type in JavaScript.
- The variables that might be created in the browsers environment when it loads a page with JavaScript in it are document and window.
- Dear grandma, values are people, variables are house, and control flow is road that moving people from one house to another house.
- Functions are groups of code that can be used whenever we want. We need them whenever we want to use it in many places. It is to reduce man made mistake and our life easy.
Homework
Exercises 2.1
It is true. As (false || true) && !(false && true).
Exercises 2.2
Write a program that calculates and shows the value of 210 (2 to the 10th power).
Exercises 2.3
With some slight modifications, the solution to the previous exercise can be made to draw a triangle.
Exercises 2.4
Rewrite the solutions of the previous two exercises to use for instead of while.
From Exercises 2.3
From Exercises 2.4
Exercises 2.5
Write a program to ask yourself, using prompt, what the value of 2 + 2 is. If the answer is "4", use alert to say something praising. If it is "3" or "5", say "Almost!". In other cases, say something mean.
Exercises 2.6
Add a while and optionally a break to your solution for the previous exercise, so that it keeps repeating the question until a correct answer is given.
Exercises 3.1
Write a function called absolute, which returns the absolute value of the number it is given as its argument. The absolute value of a negative number is the positive version of that same number, and the absolute value of a positive number (or zero) is that number itself.
Exercises 3.2
Write a function greaterThan, which takes one argument, a number, and returns a function that represents a test. When this returned function is called with a single number as argument, it returns a boolean: true if the given number is greater than the number that was used to create the test function, and false otherwise.
Comments
Comments powered by Disqus