Web Programming for Non-Programmers

DCI 110

Winter 2019

Credits: 4

Requirements Met: SC, DCI Minor Core Elective

GitHub Site: https://github.com/dci110w19

Class Meeting Metadata
Meets: M
W (lab)
2:45 - 4:15pm
3:15 - 4:45pm
2:45 - 4:15pm
Classroom: CGL 212
Instructor's Metadata
Instructor: Jason T. Mickel, Ph.D.
E-Mail: mickelj@wlu.edu How to Email a Professor
Phone: (540) 458-8653
Office: Leyburn M33
Office Hours: M 11:00 - 12:00
T 11:00 - 12:00
W 1:00 - 2:00
Or by appointment

JavaScript Exercise #2: Temperature Converter Enhanced25 points

Due Tuesday, March 5 @ 11:55pm


Create an object-based temperature converter that guarantees valid user input and uses a loop to display conversion along with the next 9 lower temperatures by 5.

Steps to Complete the Assignment

Make the following changes to your JavaScript:

  1. At the top of the JS panel add the following comment to prevent JSBin from prematurely ending your loop:
    // noprotect
    This is only needed in JSBin, not in later assignments in Visual Studio Code.
  2. Create an object called TempConverter with a property called tempF and set it to an initial value of 0.
  3. Add a method to TempConverter called calcTemp that converts the object's tempF property to Celsius, and returns the value calculated.
  4. Add a method to TempConverter called getTemp. It should:
    1. Prompt the user for input, being specific about what you're expecting the user to enter
    2. Use an if statement to test whether or not the temperature is a valid number. Investigate the isNaN() function.
      1. If it is NOT a number, display an error message using the alert() function to indicate the problem. Then return the boolean value false.
      2. If it IS a number, set the tempF property to the value entered by the user, call the object's displayTemp method (created in the next step), then return the boolean value true.
  5. Add a displayTemp method to display the converted temperatures. In it:
    1. Declare a variable with a brief introductory message that explains that temperatures in Fahrenheit on the left are equal to Celsius temperatures on the right.
    2. Declare a variable with no initial value assigned to it that will later contain the results of your calculations below.
    3. Write a FOR loop that — every time it runs — concatenates onto the variable in the previous step:
      • A newline character represented by a backslash followed by "n" (\n)
      • The current Fahrenheit temperature
      • Two tab characters represented by a backslash followed by "t" twice (\t\t)
      • The temperature's Celsius conversion
      The loop should run a total of 10 times. To perform the conversion, call the method calcTemp that you wrote previously.

      The loop code should update the object's property tempF each time with the next Fahrenheit value lower by 5.
    4. In the console, display the introductory message followed by the variable with your concatenated results string.
  6. Outside of the object's definition, call its getTemp() method and assign the returned value to a variable.
  7. Use a while loop to check if the returned value is false. If so, perform the above step until the returned value is true.
  8. Test with various good numbers (including 0) as well as non-numbers to ensure you get the expected results.


JavaScript should be properly formatted following coding conventions discussed in class.

Your results should look something like this:

Good user input:

Good user input for Exercise 2 Sample image for how the results of Exercise 2 should look

Bad user input:

Bad user input for Exercise 2 Error message for bad user input on Exercise 2

Grading Specifications

You will be graded on:

  1. Accurately meeting all of the specifications above
  2. Following JavaScript coding rules and conventions discussed in class and in the textbooks
  3. Correct calculation results
  4. User-friendly output

The lab will begin with a full score of 25 points and deductions will be made according to the amount and severity of errors.