General Details

Due Date: November 15, 2018 [2018-11-15, Thursday of week 12]

The following guidelines are expected for all homework submissions:

Problems From Chapter 3

  • Ch 3, #18: Let p = { x: 1, y: [ 4, {z: 2} ] }. What is p.y[1]?
  • Ch 3, #23: Draw a picture of the following object(s). don't forget to show references as arrows.
          {call: "mark", next: {call: "ready", next: {call: "set", next: {call: "go", next: null}}}}
                    
  • Ch 3, #33: In mathematics, a two-dimensional matrix is an arrangement of values in rows and columns, such as:

    982-5
    π72.86
    -2240100


    Matrices can be represented in JavaScript as arrays of arrays. Write a JavaScript array expression for the preceding matrix. Your array should have three elements, each of which is an array of four elements.
  • Ch 3, #39: Write a script that prompts for a number in base-16 and alerts its value in base-10. [HINT: find the JavaScript function that makes this problem simple.]
  • pg 68, #3 : Enter and run the die-rolling script from this chapter. Can your browser display the die face characters? If not, what is shown in their place?
  • pg 79, #1 : Draw a picture of the objects resulting from the following declaration:
          var p1 = {name: "Alice"};
          var p2 = {name: "Bob", manager: p1};
          p1.manager = p1;
                    
  • pg 79, #2 : What is the value of p2.manager.manager.manager.name in the previous question?
  • Problems From Chapter 4

  • Ch 4, #2 : Suppose your friend tells you that an expression statement consisting only of a prompt, without assigning the result to a variable, is useless. Would you agree or disagree? Explain your answer using the following script (simulating a person who speaks but does not listen) for support:
          prompt( "Hi, how are you today?" );
          alert( "Gee, that's great!" );
                    
  • Ch 4, #5 : Suppose your little sister asks you why she couldn't find a "delete statement" in the official JavaScript definition, even though she writes statements like
          delete player.winnings;
                    
    all the time. Knowing that she is the kind of kid who loves technical, precise explanations of linguistic features, what do you tell her? (Note: You have to say more than just "Delete is an operator, kiddo.")
  • Ch 4, #14: Write a script that repeatedly prompts a user to enter a word or phrase until the empty string is entered. After each (nonempty) word is entered, alert a random letter from the word. [Hint: the empty string has a length of zero.]
  • Ch 4, #17: Write a script that prompts the user for an integer (in the range 1 to 10,000 — you must check this) and reports the number of steps required in the Collatz sequence to reach the value 1. The Collatz sequence is a sequence of positive integers obeying the following rules:
    For example, if your user inputs 10, then your script should produce the value 6 because the sequence 10 → 5 → 16 → 8 → 4 → 2 → 1 involves six steps. If the initial value is 1, then you should report zero steps.
  • Ch 4, #19: Recall the example script on page 121 that produced an acronym from an array of strings. Modify this script so that instead of creating an acronym from a fixed array, the user is first prompted to enter a string. Your new scripts should then split the input string, producing an array that is then processed by the acronym-generating code from this chapter.
  • Implementation Exercises

    Exercise 1: Create a web page which has many parts and looks really "busy". You can have headers of all different sizes, paragraphs of text, tables with multiple columns and rows, images, ordered/unordered lists, and any other HTML parts that you would like to put on the page. Include a button that will create a listing of all the elements by type and display it to the footer area of the page. Write the JavaScript in a separate file

    Exercise 2: Create a web page and matching JavaScript file that will implement a simple four-function calculator. There must be a text box for entering numbers, and buttons for add, subtract, multiply, and divide. You should also have a button for "equals" like a normal calculator. You don't have to make the calculator do anything fancy like maintaining running subtotals or trigonometric functions (you can if you want!) but try to make the page function like a "real" calculator as much as you can.

    Exercise 3: Write a web page and a matching JavaScript file to solve a quadratic equation of the form "Ax2 + Bx + C", using the quadratic forumula. (Look it up in your high school algebra book if you don't remember...) The web page should have three boxes for use in entering the coefficients "A", "B", and "C", and a button to click to produce the results. You may display the results in an alert box, or on the web page, but if you opt for the alert box, you must only have one alert for all results.

    Python Programming Problems

    The following problems are from the book "Python for Everyone" by Cay Horstmann and Rance D. Necaise, ISBN 978-1-118-62613-9.

    Exercise 4: (PYTHON PROGRAMMING — Business P2.36) An online bank wants you to create a program that shows prospective clients how their deposits will grow. Your program should read the initial balance and the annual interest rate from the user. Interest is compounded monthly. Print out the balances after the first three months. Write the program in Python (obviously). Here is a sample run of the program:

       Initial balance:  1000
       Annual interest rate in percent: 6.0
       Balance after the first month: 1005.00
       Balance after the second month: 1010.03
       Balance after the third month: 1015.08
              

    Exercise 5: (PYTHON PROGRAMMING — Business P2.37) A video club wants to reward its best members with a discount based on the member's number of movie rentals and the number of new members referred by the member. The discount is in percent and is equal to the sum of the rentals and the referrals, but it cannot exceed 75 percent. Write a Python program to calculate the value of the discount. Here is a sample run:

       Enter the number of movie rentals: 56
       Enter the number of members referred: 3
       The discount is equal to: 59.00 percent
             

    Exercise 6: (PYTHON PROGRAMMING — Science P2.39) The "dew point" temperature Td can be calculated (approximately) from the relative humidity RH and the actual temperature T by the formula:

       Td = (b * f(T, RH)) / (a - f(T, RH))   where:
    
       f(T, RH) = ((a * T) / (b + T)) + ln( RH )
       a = 17.27
       b = 237.7 degrees C
             

    Write a program that reads the relative humidity (a value between 0 and 1) and the temperature in degrees Celcius, and prints the dew point value. Use the Python function "log()" to compute the natural logarithm (the "ln" in the equation). Check your calculation with a few of the values located at this page. [NOTE: you'll have to convert the temperatures to degrees F.]

    Exercise 7: (PYTHON PROGRAMMING — Science P2.43) According to the Coulomb force law, the electric force between two charged particles of charge Q1 and Q2 Coulombs, that are a distance r meters apart, is given by the formula
    F = (Q1Q2) / 4 * Π * e * r². Write a program in Python that calculates and displays the force on a pair of charged particles, based on the user input of Q1 and Q2 Coulombs, and r meters.