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:
- Convert secondInteger to an integer (Number type), then sum it with firstInteger and print the result on a new line using
console.log
. - 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
. - 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!";
16
8.32
HackerRank is the best place to learn and practice coding!
Problem Link: https://www.hackerrank.com/challenges/js10-data-types/problem