Overview

This assignment contains two tasks:

Part 1. Use this link to answer a few questions individually based on our reading.

Part 2. Solve problems by writing JavaScript code in pairs.

The first task above is to be completed individually, and the second task is a pair-programming assignment. You are required, for the remainder of this assignment, to work with a partner . See below on how to form pairs and submit your common work.

Conditionals and the Date Object

The goal of this assignment is to practice your JS skills. Specifically, you will get practice with:

  • variables
  • conditional statements
  • Date object and its methods
  • writing on the web page and on the console

Forming teams

This part of the assignment will be completed in pairs.

Use this team-forming shared document to form and declare teams.

Set up and preparation

From your download directory, get the folder named hw04. It contains materials you will use for this assignment. Open the .html and .js files provided to examine the code, in your editor. Load the html documents on your browser, and see how they look.

Note: For completing this assignment, you do not need to, and you should not edit the provided html documents. Write your js code in the js files. You will need to look at the html code to idetnify the IDs of couple of elements to use in your js code.

Task 1: which day of the week were you born?

You can use the Date object, and some of this methods, in JS to figure out which day of the week you were born.

Write a js script to do the following:

  • prompt the user for:
    • the month they were born (a value in the range 1 to 12).
    • the day of the month they were born (a value between 1 and 31).
    • the year they were born (in a four-digit format).
  • Compute the day of the week for the given date.
  • Report the day of your birth in both English and French, on the web page itself.

Testing

Test the code you have written using both partners' birthdays. Test it with today's date as well.

Do you get what expected? Write the results of these tests on the web page itself, (using the innerHTML property of a suitable element on that page).

Here is how the results of my testing look on my page:

 tests results for three cases

Task 2: Conditionals over the time of day

In this task, you will write a program to report to the user the kind of meal served in the dining hall at a certain time of day.

Your code should do the following:

  • Prompt the user for the time of their interest, by asking for:
    • the hour of the time of their interest, (in the range 0 to 23, also in the US called "Military Time")
    • and the minute of the time of their interest, an integer from 0 to 59.
  • Decide which of the following message to present to the user. The message depends on the time entered. Specifically:
    • The "Kitchen is closed" message is presented when the time entered is earlier than 8:00 AM.
    • The "Breakfast is being served" message is presented when the time entered is between 8:00AM (included), and 11:30AM (not inluded.)
    • The "Lunch is being served" message is presented when the time entered is between 11:30AM and 4:00PM (not included.)
    • The "Dinner is being served" message is presented when the time entered is between 4:00PM, and the end of the day (midnight).
  • The message should also include the time entered by the user.
  • Write the appropriate message to the console.
  • Also, present it on the web page itself.

Testing, testing...

In this task, there are a number of situations you should test, to make sure your program works correctly for any time enterd by the user. Think carefully about your testing cases! On the web page, in the appropriate area ("testingID") write the particular times you tested your code, like 7:50, 13:30, 20:00, etc.

Here is how my page looks like:

 tests results for meal times

Submission

Your folder should contain the following files:

  1. birthDay.html
  2. birthDay.js
  3. mealTime.html
  4. mealTime.js

Important Note

Please remember that both partners must submit the assignment to their accounts. Upload your files to your hw04 folder, inside the public_html/cs115-assignments folder on your cs account. Permissions have been set so that only you and the instructors/graders can see your files there.

Finally, after you have uploaded your work, use the following URLs to access your files and make sure they work approrriately when accessed from the server.

       http://cs.wellesley.edu/~yourname/cs115-assignments/hw04/birthDay.html 
http://cs.wellesley.edu/~yourname/cs115-assignments/hw04/mealTime.html
When prompted for login credentials, enter your user name and passord for your cs account.

Due Date/Time

Check the schedule for the due date. The class's Late Policy applies here. Remember that you should not modify turned in work after the due time has passed, so that when we grade it, it's not time-stamped late.

Honor Code

The Honor Code applies to this course. You are encouraged to discuss assignments with other students, the tutors, and with your instructors. However, you must solve, write up, debug, test and document the assignment on your own. In other words, it is acceptable to talk with other students in English (or any other human language), but not acceptable to use any formal language and especially not HTML, CSS or JavaScript. You should not be looking at other peoples' code or showing them yours. If you worked with others or you have obtained help from any source, you must acknowledge their contribution in writing.

Homework assignments must be your own work. You may not look at solutions from other students, either from the current offering or from past offerings.

Grading

These are the criteria we use to grade the homework:

  • Folders and files have the required names and are uploaded to the proper location.
  • Your files have comments at the top and as necessary interspersed in the code.
  • You have not modified the original HTML pages.
  • Correctness and quality of the js code.