DEV Community

Lakshya Tyagi
Lakshya Tyagi

Posted on • Edited on

6 1

JavaScript Code Daily Challenge #2

About

This is a series of JavaScript Code Daily Challenge. Each day I show a few solutions written in JavaScript. The questions are from coding practice/contest sites such as HackerRank, LeetCode, Codeforces, Atcoder and etc.

Data Types - #2
https://www.hackerrank.com/challenges/js10-data-types/problem

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();    
});

function readLine() {
    return inputString[currentLine++];
}
Enter fullscreen mode Exit fullscreen mode

Complete the function in comment

function performOperation(secondInteger, secondDecimal, secondString) {
    // Declare a variable named 'firstInteger' and initialize with integer value 4.
    const firstInteger = 4;

    // Declare a variable named 'firstDecimal' and initialize with floating-point value 4.0.
    const firstDecimal = 4.0;

    // Declare a variable named 'firstString' and initialize with the string "HackerRank".
    const firstString = 'HackerRank ';

    // Write code that uses console.log to print the sum of the 'firstInteger' and 'secondInteger' (converted to a Number        type) on a new line.


    // Write code that uses console.log to print the sum of 'firstDecimal' and 'secondDecimal' (converted to a Number            type) on a new line.


    // Write code that uses console.log to print the concatenation of 'firstString' and 'secondString' on a new line. The        variable 'firstString' must be printed first.

}
Enter fullscreen mode Exit fullscreen mode
function main() {
    const secondInteger = readLine();
    const secondDecimal = readLine();
    const secondString = readLine();

    performOperation(secondInteger, secondDecimal, secondString);
}
Enter fullscreen mode Exit fullscreen mode

AWS GenAI LIVE image

How is generative AI increasing efficiency?

Join AWS GenAI LIVE! to find out how gen AI is reshaping productivity, streamlining processes, and driving innovation.

Learn more

Top comments (3)

Collapse
 
lakshyatyagi24 profile image
Lakshya Tyagi • Edited
    function performOperation(secondInteger, secondDecimal, secondString) {
        const firstInteger = 4;
        const firstDecimal = 4.0;
        const firstString = 'HackerRank ';

        const sum=firstInteger+parseInt(secondInteger);
        console.log(sum)

         console.log(firstDecimal+parseFloat(secondDecimal))

        console.log(firstString+secondString)       
    }
Enter fullscreen mode Exit fullscreen mode
Collapse
 
joachimzeelmaekers profile image
Joachim Zeelmaekers

Nice read! If you want to improve the readability you can use js to the first 3 backticks to add syntax highlighting! It would look like this:

function main() {
    const secondInteger = readLine();
    const secondDecimal = readLine();
    const secondString = readLine();

    performOperation(secondInteger, secondDecimal, secondString);
}
Enter fullscreen mode Exit fullscreen mode
Collapse
 
lakshyatyagi24 profile image
Lakshya Tyagi

Thanks Joachim Today i get to know something knew and it's really interesting

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay