Master HackerRank JavaScript Print with This Ultimate Guide

Bobby Jul 13, 2026

Welcome to the realm of coding challenges and learning! Today, we're going to explore a crucial aspect of JavaScript, essential for interactive web development: the console.log() function. This function, much like its name suggests, allows us to log messages to the console. It's an invaluable tool for debugging, testings, and even day-to-day coding, enabling you to monitor the progress of your JavaScript code in real-time.

javascript
javascript

As a platform that offers coding challenges and quizzes, HackerRank understands the importance of this function. Hence, they often challenge users to utilize console.log() for simple output tasks. So, let's dive into a comprehensive guide on 'HackerRank JavaScript Print' using console.log().

JavaScript Full Notes Every Beginner Must Save πŸ’‘
JavaScript Full Notes Every Beginner Must Save πŸ’‘

Understanding console.log()

Before we delve into the HackerRank challenges, let's understand the basics of console.log(). It's a built-in function in JavaScript that can be used to print the output of a variable or an expression to the console. The basic syntax is:

JavaScript Cheatsheet for Beginners | Learn JS Fast (One-Page Guide)
JavaScript Cheatsheet for Beginners | Learn JS Fast (One-Page Guide)

console.log(expression)

Printing Strings

a black screen with white text on it
a black screen with white text on it

You can print any string by wrapping it in quotes. For instance, to print "Hello, World!", you can write:

console.log("Hello, World!")

Printing Numbers

πŸš€ JavaScript Cheat Sheet for Beginners & Intermediate Developers | Quick Reference Guide
πŸš€ JavaScript Cheat Sheet for Beginners & Intermediate Developers | Quick Reference Guide

Just like strings, you can also print numbers directly. The below code will print the number 2:

console.log(2)

HackerRank JavaScript Print Challenges

JavaScript Web Development Cheat Sheet: Your Essential Guide - Connect 4 Programming
JavaScript Web Development Cheat Sheet: Your Essential Guide - Connect 4 Programming

HackerRank offers numerous challenges that involve using console.log() to print the desired output. Let's explore a few.

Hello, World!

Javascript Window.print()
Javascript Window.print()
an image of a computer screen with code numbers on it and the text,'to do this is a different file
an image of a computer screen with code numbers on it and the text,'to do this is a different file
javascript?
javascript?
JavaScript Explained: Why It’s the Language of the Web
JavaScript Explained: Why It’s the Language of the Web
an image of a computer screen with text on it
an image of a computer screen with text on it
an image of a computer screen with some type of text on it, and two different colors
an image of a computer screen with some type of text on it, and two different colors
a poster with many different types of information
a poster with many different types of information
How To Print A Page Or Section in Javascript
How To Print A Page Or Section in Javascript
JavaScript Fundamental
JavaScript Fundamental
Wallpaper JavaScript
Wallpaper JavaScript
an image of a computer screen with many lines and numbers on it, all in different colors
an image of a computer screen with many lines and numbers on it, all in different colors
JavaScript Cheat Sheet You Must Save | Beginner Friendly Guide
JavaScript Cheat Sheet You Must Save | Beginner Friendly Guide
hackerrank javascript print
hackerrank javascript print
JavaScript Basics in 1 Image ⚑
JavaScript Basics in 1 Image ⚑
the text error is written in white on a black background
the text error is written in white on a black background
a diagram showing the different types of web pages and their contents in each section
a diagram showing the different types of web pages and their contents in each section
Javascript Stickers
Javascript Stickers
a black and white poster with text on it
a black and white poster with text on it

The classic "Hello, World!" challenge involves printing "Hello, World!" as the output. Here's how you can do it using console.log():

console.log("Hello, World!")

What is your name?

This challenge involves asking for a user's name and printing "Hello, ". Here's a simple way of achieving this using console.log() and prompt:

let name = prompt("What is your name?");
console.log("Hello, " + name);

Calculate the sum

This involves prompting the user to enter two numbers, then printing their sum. Here's how:

let num1 = parseFloat(prompt("Enter first number:"));
let num2 = parseFloat(prompt("Enter second number:"));
console.log(num1 + num2);

Area of a Triangle

This challenge involves calculating the area of a triangle given the base and height, and then printing it. Here's how you can do that:

let base = parseFloat(prompt("Enter the base of the triangle:"));
let height = parseFloat(prompt("Enter the height of the triangle:"));
console.log("The area of the triangle is " + (base * height) / 2);

As you've now seen, console.log() is an essential part of JavaScript that also plays a significant role in coding challenges on platforms like HackerRank. Keep practicing and exploring to become proficient in JavaScript and its numerous functionalities. Happy coding!