Self-Test

  1. Create a fully-specified HTML page (including !doctype and outer-level html tags) with title and main text "Hello world!" Then, link to a JavaScript file called "hello.js" that also prints out "Hello world!" to the browser console.
  2. Write a function in JavaScript that takes in a number, and returns a boolean corresponding to whether that number is prime.
  3. Let's say you have an array of integers—say [0, 43, -123, 4, -60, 32]—and you want to find the sum of only the odd integers in the array. Write two JavaScript programs to do so: one that doesn't use functional programming constructs (i.e. map, filter, and/or reduce), and one that does.
  4. The following is one way to represent a note:

    let myNote = {
      "midiNumber": 60,
      "duration": "4n",
      "velocity": 80
    };
    

    In this example, "midiNumber" is an integer between 21 and 108, "duration" is a duration value (to simplify: one of "1n", "2n", "4n", or "8n"), and "velocity" is an integer between 0 and 127. (Computer musicians often use "velocity" as a synonym for "volume" or "loudness".)

    Create a function makeRandomNote() that returns a note with a random MIDI number, duration, and velocity within the bounds stated above. You may find the following function helpful:

    /*
     * This function gets a random integer between min and max, inclusive.  I copied
     * it from StackOverflow: https://stackoverflow.com/questions/4959975/
     */
    let getRandomInt = (min, max) => {
        return Math.floor(Math.random() * (max - min + 1)) + min;
    };
    
  5. Using your new makeRandomNote() function, make five random notes, and store them in an array, sorted by velocity. You may find this array method handy. If you can, challenge yourself to use an anonymous function when sorting the array.
  6. Write a function that takes in a note of the form above, and determines whether or not that note is in the G major scale. (Hint: you may want to review the material on pitch classes and MIDI numbers.)
  7. Look at the following snippet from an HTML document.

    <button id="toggler">Show/Hide Text</button>
    <p id="text">I'm being toggled!</p>
    

    Make it so that when you click on the button, you toggle the text. If you are using jQuery, look up $().toggle(); if you are not using jQuery, look up CSS "display". (Also, if you want to cheat, look at the source code for this very page!)