#Javascript Function Exercises
- Navigate to this project in your terminal
- Run
http-server
- Open http://localhost:8000 in Chrome
You should see failing tests.
Create 20 functions by following the comments in functions.js
.
Write all of functions below in functions.js
After you write each function:
- Save
functions.js
. - Reload http://localhost:8000 in Chrome.
- Check if your test passes.
- If it passes, commit your work.
Converts a number a string.
Parameters
n: number
Returns: string, the number as a string
Adds one to a given number
Parameters
n: number
Returns: number
Subtracts one from a given number
Parameters
n: number
Returns: number
Adds two numbers.
Parameters
x: number
y: number
Returns: number, the sum
Subtracts the second number from the first.
Parameters
x: number
y: number
Returns: number, the difference
Multiplies two numbers.
Parameters
x: number
y: number
Returns: number, the product
Divides the first number by the second.
Parameters
x: number
y: number
Returns: number, the quotient
Multiplies a number by itself.
Parameters
x,: number, number to be squared
Returns: number, squared
Prints out the equation: (i.e.) "1 + 5 = 6" or "8 / 2 = 4". Returns the result.
Parameters
operation: string, "add", "subtract", "multiply", or "divide"
x: number
y: number
Returns: number, the result
Returns true if a
is greater than b
Parameters
a: number
b: number
Returns: boolean, a
is larger than b
Returns true if a
is less than b
Parameters
a: number
b: number
Returns: boolean, a
is smaller than b
Returns true if a
and b
are equal
Parameters
a: number
b: number
Returns: boolean, the numbers are equal
Returns the smallest value of two numbers.
Parameters
a: number
b: number
Returns: number, the smallest number
Returns the largest value of two numbers.
Parameters
a: number
b: number
Returns: number, the largest number
Returns true if n
is even.
Parameters
n: number
Returns: boolean, the number is even
Returns true if n
is odd.
Parameters
n: number
Returns: boolean, the number is odd
Returns a letter grade. "A": 90-100% "B": 80-89% "C": 70-79% "D": 60-69% "F": 0-59%
Parameters
score: number
total: number, maximum possible score
Returns: string, the score represented as a letter grade
Checks if a restaurant
object has a reviews
field.
If it does, increase it by 1. If it does not,
set its reviews
field to 1.
Parameters
restaurant: object, represents a restaurant
Joins two strings with a space.
Parameters
word1: string
word2: string
Returns: string, joined the words joined with a space
Returns a circle object with the properties circumferance
and area
.
Use Math.PI for the value π.
Parameters
radius: number
Returns: object, circle
After all your tests pass, practice calling functions by following the comments in script.js
.