CIS 111 Web Programming, Project 3 Solution

CIS 111 Web Programming, Project 3 Solution

Overview
Project 3 requires you to write web programs that use selection statements, loops and functions, which are described in Ch. 3 and 4 of our textbook.
Learning Outcomes
After completing this project, you will:
• Understand the four steps of the WebDev Workflow*.
• Understand Command-Line JavaScript and Client-Side JavaScript programs.
• Be able to use selection statements to solve programming problems.
• Be able to use loops to solve programming problems.
• Be able to write functions that accept arguments and return values.
Requirements
1. Practice with selection, loops and functions - 50 points
Name and location of the file on the server: 111/p3/functions.js
All of the following are Command-Line JavaScript exercises. None of these functions
will contain i/o (no code using prompt, console.log or alert). You do not need to
create a web page for this part of the project. Store the code for each exercise in
functions.js.
A) Write a value-returning function named isEven that takes an integer as an
argument and returns true if the integer is even, false if it is not. Like this:
isEven(4) = true
isEven(5) = false
B) Write a function named kindOfDay that takes the name of a day of the week as an  argument and returns “Weekend”, “Weekday”, or “Not a day” depending on the day  passed to it. Like this:
dayOfWeek(“Sunday”) = Weekend
dayOfWeek(“Monday”) = Weekday
dayOfWeek(“Tuesday”) = Weekday
dayOfWeek(“Wednesday”) = Weekday
dayOfWeek(“Thursday”) = Weekday
dayOfWeek(“Friday”) = Weekday
dayOfWeek(“Saturday”) = Weekend
dayOfWeek(anything else) = Not a day
C) Write a function named count that takes an integer as an argument and returns a  string with the integers from 1 to the number passed as an argument. Like this:
(Hints: use a loop, return a string)
count(5) = 1, 2, 3, 4, 5
count(3) = 1, 2, 3
CIS 111 Web Programming, Project 3
D) Write a function named countChange that takes numbers of quarters, dimes,
nickels, and pennies as arguments (in that order) and returns their total value, like
this:
countChange(1, 1, 1, 1) = $0.41
countChange(3, 1, 2, 3) = $0.98
countChange(4, 2, 3, 7) = $1.42
2. Loop practice: a multiplication web page – 50 points
Files to upload: 111/p3/multiplication.js
111/p3/multiplication.html
A) Command-Line JavaScript. Write a function named multiply, save it in a file named  multiplication.js. The function will take an integer as an argument and return a string  containing that number multiplied by all the integers between 1 and 10, like this:
Multiply(6) = 1 * 6 = 6
2 * 6 = 12
3 * 6 = 18
and so on through 10
10 * 6 = 60
Multiply(8) = 1 * 8 = 8
2 * 8 = 16
3 * 8 = 24
and so on through 10
10 * 8 = 80
B) Create a web page named multiplication.html in your p3 folder that allows the user  to enter a positive integer. When the user clicks a button, that number multiplied by  the integers 1 through 10 will be displayed on the web page. You will add code to  multiplication.js to get input from a text box and display the output on the web page.
Client-Side Debugging Tip: If nothing happens when you click the button, remember  to open the DevTools console and check for error messages.
* The 111 WebDev Workflow
Here is the CIS 111 Web Development Workflow. Memorize these 4 steps.
1. Edit. Use a Text editor to create a web page (.html and .js files) on your computer.
2. Preview. Open the web page on your computer and check it using Chrome.
3. Upload. Copy all project files (.html, .js, .png, etc.) to the server using an SFTP client  (CyberDuck, Sublime, FileZilla, ...). This is also known as publishing the web page.
4. Test. Use Chrome to open your web page that is on the server. Do not use
CyberDuck, use Chrome. Make sure that this web page is correct, because that is what  will be graded.
Powered by