JavaScript代写:CIS111 Command Line JavaScript

关于JavaScript的基础练习题目,在命令行中执行运行JS脚本,计算结果。

Problem 1

All of the following Command-Line JavaScript exercises. You do not need to create a web page for this part of the project. Store the code for each exercise in functions.js in your p3 folder.

A) Write a function named isSnakeEyes that accepts two numbers and returns true if both numbers are 1, false

1
2
isSnakeEyes(6, 5) => true
isSnakeEyes(1, 1) => true

B) Write a function named isVowel that accepts a character (upper or lower case) and returns true if it’s a vowel, false otherwise. Example:

1
2
3
isVowel("A") => true
isVowel("y") => true
isVowel("D") => false

C) Write a function named getAmount that accepts a string in currency format (“$n.nn”) and returns the numeric value from the string. Example:

1
2
getAmount("$19.99") => 19.99
getAmount("$0.49") => 0.49

D) Write a function named countVowels that accepts a string and returns the number of vowels in contains. Example:

1
2
3
countVowels("Rhythms") => 1
countVowels("AOxomoXOa") => 9
countVowels("Nth") => 0

Since each character in the string needs to be checked, you will need to use a loop to solve this problem.

E) Write a function named sumOfDigits that accepts a positive integer and returns the sum of its digits. Example:

1
2
sumOfDigits(12345) => 15
sumOfDigits(8675309) => 38

Since the function accepts a number of any length, you will need to use a loop to solve this problem.

F) Write a function named rollSnakeEyes that accepts no arguments and returns the number of rolls it took to get double 1’s. Example:

1
2
rollSnakeEyes() => 12
rollSnakeEyes() => 2

G) Write a function pizzaPSI that accepts three numbers (the cost of a pizza, the diameter in inches, and the number of toppings) and returns the cost Per Square Inch, in currency format. Each topping costs $1.25. Example:

1
2
pizzaPSI(28.00, 17, 3) => "$0.14 PSI"
pizzaPSI(17.00, 12, 2) => "$0.17 PSI"

Problem 2

Client-Side JavaScript requires two files: a web page file (.html) and a JavaScript file (.js). Store both files in your p3 folder in the 111 folder on your computer and the uoregon.edu server.
A) Create a web page named pizzaPSI.html that looks like this, and allows the user to enter a pizza’s properties.
B) Create a file named pizzaPSI.js in your p3 folder. When the Go Figure! button is clicked, the pizza cost Per Square Inch is calculated and displayed as shown.

Client-Side Debugging Tip

If nothing happens when you click the button, always remember to open the DevTools console and check for error messages.

When your web app is not working correctly: Your first stop is always the DevTools console.

The 111 WebDev Workflow

Here is the CIS 111 Web Development Workflow. Memorize these 4 steps.

  1. Edit. Use your code editor to create a web page (.html and .js files) on your computer.
  2. Preview. Open the web page on your computer using Chrome. When it is perfect, and not before, go to the next step.
  3. Upload. Move all project files (.html, .js, .png, .jpg, …) to the server using Fugu or CyberDuck. This is also known as Publishing or Deploying the web page.
  4. Test. Use Chrome to open your web page that is on the server. Do not use CyberDuck– use Chrome.