Functions in JavaScript

Day 1: Functions in JavaScript | HackerRank Solutions

Functions in JavaScript!!!

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

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

So on this day 1: functions in JavaScript you simply have to write a function in which you have to do factorial. In simpler words they want you to write factorial function.

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: Functions in JavaScript

Functions 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.


Today, we’re discussing JavaScript functions. Check out the attached tutorial for more details.


Implement a function named factorial that has one parameter: an integer, n!. It must return the value of  (i.e.,  factorial).

Input Format

Locked stub code in the editor reads a single integer,n! , from stdin and passes it to a function named factorial.


  • 1 <= n <= 10

Output Format

The function must return the value of n!.

Sample Input 0


Sample Output 0


Explanation 0

We return the value of 

4! = 4 x 3 x 2 x 1 = 24.

Solution – Day 1: Functions in JavaScript

 * Create the function factorial here
function factorial(n){
    let num=1;
    if(n==1 || n==0){
        return num;
        for(let i = 1; i <= n; i++){
      num = num * i;
    return num;

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