HackerRank Data Types | JS Solution

HackerRank Data Types | JS Solution


HackerRank detailed problem description can be found here.

Inputs & Outputs

{string} readLine() #1
{string} readLine() #2
{string} readLine() #3

print {number} sum of `i` and `int`
print {string} sum of `d` and `float`
print {string} concat `s` and `str`

Test Case

int = parseInt('12');
float = parseFloat('4.0');
str = 'is the best place to learn and practice coding!';

JavaScript Solution

// Declare second integer, float, and String variables.
let int;
let float;
let str;

// Read and save an integer, float, and String to your variables.
int = parseInt(readLine());
float = parseFloat(readLine());
str = readLine();

// Print the sum of both integer variables on a new line.
console.log(int + i);

// Print the sum of the float variables on a new line.
console.log((float + d).toFixed(1)); // toFixed() method returns String data type

// Concatenate and print the String variables on a new line
console.log(s + str);
// The 's' variable above should be printed first.


  1. Built-in methods parseInt(), parseFloat() and toFixed()
  2. Data Types algorithm by HackerRank