1 min to read
10 Days of JavaScript Day 5: Inheritance & Arrow Functions
Day 5 of 10 Days of JavaScript
challenge on Hackerrank is Inheritance, Template Literals, and Arrow Functions.
In this series, I will be sharing my solutions to the challenges.
Day 5: Inheritance
Perform the following tasks using the Rectangle
class and inheritance concept.
- Add an
area
method toRectangle
’s prototype. - Create a
Square
class that satisfies the following:- It is a subclass of
Rectangle
. - It contains a constructor and no other methods.
- It can use the
Rectangle
class’ area method to print the area of aSquare
object.
- It is a subclass of
Day 5: Template Literals
The code in the editor has a tagged template literal that passes the area and perimeter of a rectangle to a tag function named sides. Recall that the first argument of a tag function is an array of string literals from the template, and the subsequent values are the template’s respective expression values.
Complete the function in the editor so that it does the following:
- Finds the initial values of
s1
ands2
by plugging the area and perimeter values into the formula:s = (P +- sqrt(P^2 - 16 * A)) / 4
- where
A
is the rectangle’s area andP
is its perimeter.
- Creates an array consisting of
s1
ands2
and sorts it in ascending order. - Returns the sorted array.
Day 5: Arrow Functions
Complete the modifyArray
function so that it returns a new array based on the array
parameter, but where each element has been multiplied by 2
. Use the arrow function syntax.
- If the elmement is even, multiply it by 2.
- If the element is odd, multiply it by 3.