Distance Calculator

Enter the latitude and longitude coordinates (in decimal degrees) for your two points of interest.

Guessing Game

The computer will choose a random number between 1 and 100. It's your job to guess the number!

Instructions:

  1. Click 'Let the guessing game begin!' to start the game.
  2. Type your guess in the form and hit the 'Submit your guess.' button.
  3. Keep trying until you get the right number.
  4. Click 'Let the guessing game begin' again to reset the game.


Warm-Up Questions

Exercise 1

Spec: Write a loop that displays (on the console) the powers of 2 (i.e., 2 to the n-th power) for all numbers (n) ranging from 0 to 20. Your output should be displayed in user-friendly text, i.e., "2 to the power of 8 is 256."

Code:

                    for (i = 0; i < 21; i++)
                    {   
                        console.log(`2 to the power of ${i} is ${2 ** i}`);
                    }
                

Exercise 2

Spec: Write a function that implements the Pythagorean theorem and returns the length of the hypotenuse of a right triangle using the lengths of the sides, which are to be passed in to the function as arguments.

Implementation:

function pythagorianHelper(a, b)
{
    return Math.sqrt(a**2 + b**2);
}  
// Test with some famous: Pythagorean triples:
console.log(pythagorianHelper(3, 4));
console.log(pythagorianHelper(12, 5));
                

Exercise 3

Spec: Write a function that can be used to test whether a number is even or odd, and call this function on at least one even number and one odd number to demonstrate that it works properly. The function should return a value of true if the number is even and false if the number is odd.

Implementation:

function parityTester(x)
{
    if ((x % 2) == 0) return true;
    return false;
}

console.log(parityTester(1))
console.log(parityTester(13))
console.log(parityTester(16))
console.log(parityTester(-16))
console.log(parityTester(-9))
                

Exercise 4

Spec: Write a function that converts Degree-Minute-Second (DMS) coordinates to decimal degrees. The function should accept degrees, minutes, and seconds as three separate arguments.

Implementation:

function degreeConverter(d, m, s)
{
    // 3600 seconds in a degree:
    let decimalSeconds = s / 3600;
    let decimalMinutes = m / 60;
    
    return decimalSeconds + decimalMinutes + d;
}

console.log(degreeConverter(-55, 5, 34));
console.log(degreeConverter(0, 30, 0)); // Should return 0.5
console.log(degreeConverter(0, 0, 360)); //Improper seconds
                

Exercise 5

Spec: Write a statement that changes the HTML content of a <div> tag.

Implementation:

Suppose your div tag has an id attribute of "myDiv1":

<div id="myDiv1">Original text, boring :(</div>
                

You could include the following JavaScript to change the displayed text:

document.getElementById("myDiv1").innerHTML = "New text, hooray!";
                

*Tabset code adapted from lessons on W3 Schools.