In: Computer Science
1. In your program, demo the split() method for strings and attach it to one of the buttons.
"Numbers" lesson
2. Check if 3===3.0. Why?
3. Find the number of zeros such that 3===3.000…01. Why can this happen?
4. If var x=123e15, and var y=123e-15, does x===x+y? why?
5. What is typeof NaN? Comment on its (il)logicality.
"Number Methods" lesson
6. What is the hexadecimal number ff (written in JavaScript as 0xff) in base 10?
7. Write all the numbers from 0 to 20 in hexadecimal form. If not sure you can always use a for loop and (if the index variable is i), print out i.toString(16).
8. What is 0xff.toString()? Why?
9. What is (35).toString(36)? Why?
10. What is (35).toString(37)? Why?
11. Give a call to alert() that gives $0.99 + 7% (sales tax, say) of $0.99.
12. Why does (0.99+0.07*0.99).toFixed(2) give the price if it costs $0.99 + 7% sales tax?
13. What is Number(true)?
14. What is Number(undefined)? Why?
15. What is parseInt(0xff)? Why?
16. The Number entity contains useful stuff. What is the value of Number.MAX_VALUE? Is it big?
17. Consider the hexadecimal (base 16) number 9a. In a JavaScript program you would write it as: 0x9a. How would you write it in the more familiar base 10? Here is how to solve this.
a. Recall that a "normal" base 10 number has a ones place, a tens place, a hundreds place, a thousands place, etc. Another way to put it is, it has a 100's place (100=1), a 101's (101=10), a 102's place (102=100), a 103's place (103=1,000), etc. Similarly, a base 16 number has a 160's place (160=1), a 161's (161=16), a 162's place (162=16x16=256), a 163's place (163=16x16x16=4,096), etc.
b. So the base 16 number 9a has an "a" in the 1s place and a 9 in the 16s place.
c. It has "a" 1s and 9 16s, so just calculate (a*1)+(9*16).
d. What number is "a"? Well, base 10 numbers are made with 10 numeral symbols (0 1 2 3 4 5 6 8 9). Similarly, base 16 numbers are made with 16 numeral symbols (0 1 2 3 4 5 6 7 8 9 a b c d e f). An "e" for example has the value of fifteen. Base 2 numbers are made with 2 numeral symbols (0 1). Base 36 uses 36 symbols (0...9 and a...z). In everyday use we get up to base 60 (for measuring time at 60 seconds per minute, 60 minutes per hour) but rather than use 60 different symbols we use other means, as you might have noticed.
e. You can check your answer in JavaScript using the toString() method:
var num = 128;
num.toString(16);
will provide a string for the base 10 number 128 rendered as a base 16 number. So you can see if toString() will convert your answer and give the string "9a". If it does, you got the right answer.
18. So far we have looked at calculating a conversion from base 16 numbers into base 10. The same idea applies to converting any base into base 10. What is the base 8 number 7564 in base 10?
19. What is the binary number 11101111 in base 10?
20. Next, consider converting base 10 numbers into base 16 or any other base.
Calculate what the base 10 number 1000 is in base 16 (show your work, without using JavaScript). You can check your answer JavaScript using toString() if you like. Here's how to calculate it.
a. 163=4096, and there are no 4096s in 1000, so there is no fourth digit in the answer, since what you really need are the three digits for 162, 161, and 160. How many 162s are in 1000? 162=256, so the question then is how many 256s are in 1000? The answer is 3, with a remainder. So the partial answer is: 3 _ _ . Fill in the 2 blanks.
b. The 3 is the number of 162s or 256s in 1000, which leaves 1000-3*256 = 232 unaccounted for.
c. The next digit is for the number of 161=16s we need. We can fit 14 of them into 232: 14*16=224, with a remainder of 8 that is not yet accounted for. 14 is written "e" in base 16, so the answer so far is: 3e_ and we have one blank left to fill.
d. The 160 or 1s place holds the number of 1s we need. 8 of them are needed to fill up the remainder of 8 that we have to deal with, so the answer is: 3e8. Thus
num = 1000;
num.toString(16);
should give the string "3e8".
21. What is 2000 in base 16 (hexadecimal)? Calculate it without using JavaScript and show your work.
22. Do this the fast way using toString(). What is the base 10 number 128 in base 2?
23. Do this the fast way using toString(). What is the base 10 number 128 in base 36? toString() won't go above 36.
24. What is 200,000,000 in hexadecimal? Do it the fast way in JavaScript unless you have a lot of extra time on your hands.
The "Random" lesson
25. Check out https://www.w3schools.com/js/tryit.asp?filename=tryjs_random_function. Explain how it works.
26. Give a call to Math.floor() that returns a random integer from 1 to 10, inclusive (inclusive means it could return 1, 10, or any integer in between).
Dear Student ,
You have posted 26 Questions. Out of which are only allowed to answer 4 Sub Parts.
But for You I am going to answer as many as I can in the Given Time To Me .
Thank You.
1st Question to use Split Method.
2.If 3==3.0 Answer is Yes
Proof:
Question 3 Answer :.Finding the Number of Zeros will lead to infinite Loop .
Because Value of 3 does not change when there are so many zeros in between.
Question 4 Answer:
x=123e15
y=123e-15
Yes x==x+y
Proof :
Question Number 5 Answer:
The type of NaN , which stands for Not a Number is, surprisingly, a number. The reason for this is, in computing, NaN is actually technically a numeric data type. However, it is a numeric data type whose value cannot be represented using actual numbers