Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For each of the following, write a function that takes the given arguments, and returns or produces (e.g., console.log) the given result. Given r (radius)

For each of the following, write a function that takes the given arguments, and returns or produces (e.g., console.log) the given result.

Given r (radius) of a circle, calculate the area of a circle (A = * r * r).

Simulate rolling a dice using random(). The function should allow the caller to specify any number of sides, but default to 6 if no side count is given: roll() (assume 6 sided, return random number between 1 and 6) vs. roll(50) (50 sided, return number between 1 and 50).

Write a function that converts values in Celcius to Farenheit: convert(0) should return "32 F".

Modify your solution to the previous function to allow a second argument: "F" or "C", and use that to determine what the scale of the value is, converting to the opposite: convert(122, "F") should return "50 C".

Function taking any number of arguments (Numbers), returning true if they are all less than 50: isUnder50(1, 2, 3, 5, 4, 65) should return false.

Function allowing any number of arguments (Numbers), returning their sum: sum(1, 2, 3) should return 6.

Function allowing any number of arguments of any type, returns true only if none of the arguments is falsy. allExist(true, true, 1) should return true, but allExist(1, "1", 0) should return false.

Function to create a JavaScript library name generator: generateName("dog") should return "dog.js"

Function to check if a number is a multiple of 3 (returns true or false)

Check if a number is between two other numbers, being inclusive if the final argument is true: checkBetween(66, 1, 50, true) should return false.

Function to calculate the HST (13%) on a purchase amount

Function to subtract a discount % from a total. If no % is given, return the original value.

Function that takes a number of seconds as a Number, returning a String formatted like "X Days, Y Hours, Z Minutes" rounded to the nearest minute.

Modify your solution above to only include units that make sense: "1 Minute" vs. "3 Hours, 5 Minutes" vs. "1 Day, 1 Hour, 56 Minutes" etc

Function that takes any number of arguments (Numbers), and returns them in reverse order, concatenated together as a String: flip(1, 2, 3) should return "321"

Function that takes two Numbers and returns their sum as an Integer value (i.e., no decimal portion): intSum(1.6, 3.333333) should return 4

Function that returns the number of matches found for the first argument in the remaining arguments: findMatches(66, 1, 345, 2334, 66, 67, 66) should return 2

Function to log all arguments larger than 255: showOutsideByteRange(1, 5, 233, 255, 256, 0) should log 256 to the console

Function that takes a String and returns its value properly encoded for use in a URL. prepareString("hello world") should return "hello%20world"

Using the previous function, write an enclosing function that takes any number of String arguments and returns them in encoded form, concatenated together like so: "?...&...&..." where are the encoded strings. buildQueryString("hello world", "goodnight moon") should return "?hello%20world&goodnight%20moon"

Function that takes a Function followed by any number of Numbers, and applies the function to all the numbers, returning the total: applyFn(function(x) { return x * x;}, 1, 2, 3) should return 14.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Technology. Refer to Case

Answered: 1 week ago