Assignment 1 (pdf)

Make sure to test all your answers in the console.

  1. Review the documentation for parseInt. Then answer the following questions.
    1. The string "ffff" represents a hexadecimal number. Write an expression parseInt(...) that would return the number that this string represents.
    2. Do the same for the string “10010101” that represents a number in binary format.
    3. What does parseInt do if it is called with a string it cannot properly process?
  2. Look at the Math library. Then answer the following questions (do NOT use experimental methods; those marked with a little symbol on their side):
    1. Write the expression that would compute the circumference of a circle of radius r.
    2. Write an expression that returns a boolean telling us if the number x is less than 1 in absolute value.
    3. Use Math.log to write an expression that would compute the base 2 logarithm of the number n.
    4. Combine Math.random and Math.floor to write an expression that produces a random integer from 0 to 2 (i.e. 0, 1 or 2).
  3. How many different types of numbers do we have in Javascript? (Circle correct one)
  4. The expression x/+0 for x a finite number can have 3 different values, depending on what value x has. List all 3 values along with examples of x values that produce them.
  5. True or False: Javascript can only be run inside a web browser.