10 Days Of JavaScript

Day 0: Hello World! Solution

Introduction

Hello Friends! In this article, I’m going to share with you the Hackerrank 10 Days of JavaScript solution for Day 0: Hello World! This challenge will get you familiar with basic JavaScript concepts and its lexical structure.

If you’re interested in more solutions, check out the Day 9: Binary Calculator Solution by following the link.

 

Day 0: Hello World! Solution

 

Objective:

The goal of this challenge is to:

  1. Use the console.log() function to print the string “Hello, World!”.
  2. Use console.log() to print the contents of a variable passed to the function as a parameter.

Task:

A function named greeting is provided in the editor. It has one parameter, parameterVariable. To complete the challenge:

  • Print Hello, World! on the first line.
  • Print the contents of parameterVariable on the second line.

Input Format:

The function will receive:

  • Data Type: string
  • Parameter: parameterVariable
  • Description: A single line of text containing one or more space-separated words.

Output Format:

  • The first line should print: Hello, World!
  • The second line should print the contents of the parameterVariable.

Sample Input 0:

Welcome to 10 Days of JavaScript!

Sample Output 0:

Hello, World!
Welcome to 10 Days of JavaScript!

 

Solution – Day 0: Hello, World!

Here’s the solution for the challenge:

/**
* A line of code that prints "Hello, World!" on a new line is provided in the editor. 
* Write a second line of code that prints the contents of 'parameterVariable' on a new line.
*
* Parameter:
* parameterVariable - A string of text.
**/
function greeting(parameterVariable) {
// This line prints 'Hello, World!' to the console:
console.log('Hello, World!');

// Write a line of code that prints parameterVariable to stdout using console.log:
console.log(parameterVariable);
}

Explanation:

The console.log(‘Hello, World!’) prints the string “Hello, World!” to the console.
The console.log(parameterVariable) prints the value passed to the parameterVariable to the console.

Conclusion:

By following the steps above, you’ve successfully completed the Day 0: Hello World! challenge. You now know how to use console.log() to output strings and variables in JavaScript.

This is the foundation for moving forward in the 10 Days of JavaScript series. Keep practicing and you’ll master JavaScript in no time!