arithmetic operators in javascript

Day 1: Arithmetic Operators in Javascript| HackerRank Solutions

Arithmetic operators in javascript!!!

Hello programmers, today we are sharing proper solutions with all test cases passed of 10 Days of JavaScript by HackerRank.

As you all know JavaScript is the most popular and the most challenging programming language to conquer but nowadays it’s not. There are some amazing platforms where they provide challenges on different languages and HackerRank is one of them.

So in this Day1: Arithmetic Operators in JavaScript HackerRank Solution we will discuss how we can solve this problem very easily. Basically, we have to complete two functions i.e. getArea() and getPerimeter().

In the getArea() function we have to return the area of a rectangle and in the getPerimeter() function return the perimeter of a rectangle.

Before checking out the solution it’s highly recommended to do it by yourself first because these challenges will help you to think about how to deal with these real-world problems.

Let’s get started.

Here are a couple of related posts you may find helpful, too:

  1. Day 0: Hello, World! in Javascript| HackerRank Solutions
  2. Day 0: Data Types HackerRank Solution| Amazing 10 Days of JavaScript
  3. How to make money through coding? 9 Easy Ways To Make Money.
  4. 15+FREE Stuff For College Students Using Your College ID.
  5. how to get rich by coding? I make $100 every month from coding

Problem: Arithmetic Operators in Javascript

Arithmetic Operators in Javascript

Overview: 10 Days of JavaScript

This series focuses on learning and practicing JavaScript. Each challenge comes with a tutorial article, and you can view these articles by clicking either the Topics tab along the top of the article icon in the right-hand menu.

Objective

In this challenge, we practice using arithmetic operators. Check out the attached tutorial for resources.

Task

Complete the following functions in the editor below:

  1. getArea(length, width): Calculate and return the area of a rectangle having sides length and width.
  2. getPerimeter(length, width): Calculate and return the perimeter of a rectangle having sides length and width.

The values returned by these functions are printed to stdout by locked stub code in the editor.

Input Format

image
image

Constraints

  1. 1 <= length, width <= 1000
  2. length and width are scaled to at most three decimal places.

Output Format

image

Sample Input 0

3
4.5

Sample Output 0

13.5
15

Explanation 0

The area of the rectangle is length x width = 3 x 4.5 = 13.5.
The perimeter of the rectangle is 2 x (length + width) = 2 x (3 + 4.5) = 15.

Solution – 10 Days of JavaScript Hackerrank Solutions

/**
*   Calculate the area of a rectangle.
*
*   length: The length of the rectangle.
*   width: The width of the rectangle.
*   
*	Return a number denoting the rectangle's area.
**/
function getArea(length, width) {
    let area;
    // Write your code here
    area= length*width;
    return area;
}

/**
*   Calculate the perimeter of a rectangle.
*	
*	length: The length of the rectangle.
*   width: The width of the rectangle.
*   
*	Return a number denoting the perimeter of a rectangle.
**/
function getPerimeter(length, width) {
    let perimeter;
    // Write your code here
    perimeter=2*(length+width)
    return perimeter;
}

If you’d like to see some more articles, be sure to read more blogs so you can keep up to date with the latest design tutorials and tricks.

To contact me here’s my Instagram link: untied_blog

Read more

  1. how to get rich by coding? I make $100 every month from coding
  2. How To Create An App Without Coding| Build an App In 5 Minutes
  3. 11 Amazing ReactJS Projects Ideas For Beginners with Source Code
  4. How To Answer “Tell Me About Yourself”| Interview Questions.
  5. How To Answer “Strengths And Weaknesses” (Interview Questions)
  6. “Why Should We Hire You” 7+ Best Answers Examples

Leave a Comment