Skip to content

Instantly share code, notes, and snippets.

@alwaisy
Last active June 17, 2022 17:34
Show Gist options
  • Save alwaisy/2122c24dba758ee83a3765167ab7ec47 to your computer and use it in GitHub Desktop.
Save alwaisy/2122c24dba758ee83a3765167ab7ec47 to your computer and use it in GitHub Desktop.
hacker rank day2
=> testcase-0 => success
test-case-1 => failed
process.stdin.resume();
process.stdin.setEncoding('ascii');
var input_stdin = "";
var input_stdin_array = "";
var input_currentline = 0;
process.stdin.on('data', function (data) {
input_stdin += data;
});
process.stdin.on('end', function () {
input_stdin_array = input_stdin.split("\n");
main();
});
// Reads complete line from STDIN
function readLine() {
return input_stdin_array[input_currentline++];
}
function main() {
var i = 4
var d = 4.0
var s = "HackerRank "
// Declare second integer, double, and String variables.
var intt
var doub // js has no double type
var str
// Read and save an integer, double, and String to your variables.
var intt = 12
var doub = 4.0 // js has no double type
var str = 'is the best place to learn and practice coding!'
// Print the sum of both integer variables on a new line.
console.log(i+intt)
// Print the sum of the double variables on a new line.
console.log(Number(d + doub).toFixed(1))
// Concatenate and print the String variables on a new line
console.log(`${s}${str}`)
// The 's' variable above should be printed first.
}
result =>
[
Compiler Message
Success
Input (stdin)
Download
12
4.0
is the best place to learn and practice coding!
Expected Output
Download
16
8.0
HackerRank is the best place to learn and practice coding!
]
// ===> version 2 // both test0, test1 are passed
process.stdin.resume();
process.stdin.setEncoding('ascii');
var input_stdin = "";
var input_stdin_array = "";
var input_currentline = 0;
process.stdin.on('data', function (data) {
input_stdin += data;
});
process.stdin.on('end', function () {
input_stdin_array = input_stdin.split("\n");
main();
});
// Reads complete line from STDIN
function readLine() {
return input_stdin_array[input_currentline++];
}
function main() {
var i = 4
var d = 4.0
var s = "HackerRank "
// Declare second integer, double, and String variables.
var int1
var double1 // js has no double type
var str1
// Read and save an integer, double, and String to your variables.
int1 = readLine()
double1 = readLine() // js has no double type
str1 = readLine()
// Print the sum of both integer variables on a new line.
console.log(i+Number(int1))
// Print the sum of the double variables on a new line.
console.log((d + Number(double1)).toFixed(1))
// Concatenate and print the String variables on a new line
console.log(`${s}${str1}`)
// The 's' variable above should be printed first.
}
// result =>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment