[JAVASCRIPT][HackerRank]10 days of JS Day3


Contstraints

  • 0 < r <= 100
  • r is a floating-point number scaled to at most 3 decimal places.
'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++];
}

function main() {
    // Write your code here. Read input using 'readLine()' and print output using 'console.log()'.
    let r = readLine();
    const PI = Math.PI;
    // Print the area of the circle:
    
    // Print the perimeter of the circle:
    console.log(PI*r*r);
    console.log(PI*2*r);
    try {    
        // Attempt to redefine the value of constant variable PI
        PI = 0;
        // Attempt to print the value of PI
        console.log(PI);
    } catch(error) {
        console.error("You correctly declared 'PI' as a constant.");
    }
}
  • constant : 상수
  • denoting : 나타내다, 표시하다

'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++];
}

function getGrade(score) {
    let grade;
    // Write your code here
    if(score > 0 && score <= 5){
        grade = "F";
    }else if(score > 5 && score <= 10){
        grade = "E";
    }else if(score > 10 && score <= 15){
        grade = "D";
    }else if(score > 15 && score <= 20){
        grade = "C";
    }else if(score > 20 && score <= 25){
        grade = "B";
    }else if(score > 25 && score <= 30){
        grade = "A";
    }

    return grade;
}







© 2018. by sora

Powered by sora