kevnshin / js-functions

Javascript Function Exercises

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

#Javascript Function Exercises

  1. Navigate to this project in your terminal
  2. Run http-server
  3. 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:

  1. Save functions.js.
  2. Reload http://localhost:8000 in Chrome.
  3. Check if your test passes.
  4. If it passes, commit your work.

numberToString(n)

Converts a number a string.

Parameters

n: number

Returns: string, the number as a string

increase(n)

Adds one to a given number

Parameters

n: number

Returns: number

decrease(n)

Subtracts one from a given number

Parameters

n: number

Returns: number

add(x, y)

Adds two numbers.

Parameters

x: number

y: number

Returns: number, the sum

subtract(x, y)

Subtracts the second number from the first.

Parameters

x: number

y: number

Returns: number, the difference

multiply(x, y)

Multiplies two numbers.

Parameters

x: number

y: number

Returns: number, the product

divide(x, y)

Divides the first number by the second.

Parameters

x: number

y: number

Returns: number, the quotient

square(x)

Multiplies a number by itself.

Parameters

x,: number, number to be squared

Returns: number, squared

calculate(operation, x, y)

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

isGreaterThan(a, b)

Returns true if a is greater than b

Parameters

a: number

b: number

Returns: boolean, a is larger than b

isLessThan(a, b)

Returns true if a is less than b

Parameters

a: number

b: number

Returns: boolean, a is smaller than b

areEqual(a, b)

Returns true if a and b are equal

Parameters

a: number

b: number

Returns: boolean, the numbers are equal

minimum(x, y)

Returns the smallest value of two numbers.

Parameters

a: number

b: number

Returns: number, the smallest number

maximum(x, y)

Returns the largest value of two numbers.

Parameters

a: number

b: number

Returns: number, the largest number

isEven(n)

Returns true if n is even.

Parameters

n: number

Returns: boolean, the number is even

isOdd(n)

Returns true if n is odd.

Parameters

n: number

Returns: boolean, the number is odd

letterGrade(score, total)

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

incrementReviews(restaurant)

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

combine(word1, word2)

Joins two strings with a space.

Parameters

word1: string

word2: string

Returns: string, joined the words joined with a space

createCircle(radius)

Returns a circle object with the properties circumferance and area.

Use Math.PI for the value π.

Parameters

radius: number

Returns: object, circle


js-functions

After all your tests pass, practice calling functions by following the comments in script.js.

About

Javascript Function Exercises


Languages

Language:JavaScript 99.0%Language:CSS 1.0%