Day 0: Data Type! – 10 Days of Javascript – HackerRank Solutions

Embarking on the coding odyssey, we delve into the intricacies of Day 0: Hello, World!, an integral part of the 10 Days of JavaScript series on HackerRank. This article not only provides a solution but also serves as a foundational guide for those venturing into the realm of JavaScript.

Day 0: Data Type! | HackerRank Problem

Once again, if you are trying to learn javascript then don’t try this problems, these are not beginners level even though its Day 0 but its more like intermediate level.

Variables named firstInteger, firstDecimal, and firstString  are declared for you in the editor below. You must use the  operator to perform the following sequence of operations:

  1. Convert secondInteger to an integer (Number type), then sum it with firstInteger and print the result on a new line using console.log.
  2. Convert secondDecimal to a floating-point number (Number type), then sum it with firstDecimal and print the result on a new line using console.log.
  3. Print the concatenation of firstString and secondString on a new line using console.log. Note that firstString must be printed first.

There are two ways to solve this one is fastest whose solution is below, the other is type casting with parseInt and parseFloat

Day 0: Data Type! | HackerRank Solution

function performOperation(secondInteger, secondDecimal, secondString) {
    const firstInteger = 4;
    const firstDecimal = 4.0;
    const firstString = 'HackerRank ';
    console.log(firstInteger + (+secondInteger));
    console.log(firstDecimal + (+secondDecimal));
    console.log(firstString + secondString);

Day 0: Data Type! | HackerRank Output

// secondInteger = 12
// secondDecimal = 4.32
// secondString = "is the best place to learn and practice coding!";
HackerRank is the best place to learn and practice coding!

Problem Link:

Photo of author

Shreya Singh

Hey there, I'm Shreya Singh, your friendly coding enthusiast and interview prep buddy! I'm on a mission to make coding and job interviews less daunting and more exciting. With a background in computer science and a passion for problem-solving, I love sharing tips and tricks that I've picked up along the way.

Leave a comment