"JS10 Day 3: Throw"의 두 판 사이의 차이

1번째 줄: 1번째 줄:
==개요==
==개요==
;<nowiki>Day 3: Throw</nowiki>
;<nowiki>JS10 Day 3: Throw</nowiki>
* https://www.hackerrank.com/challenges/js10-throw/problem
* https://www.hackerrank.com/challenges/js10-throw/problem


9번째 줄: 9번째 줄:
----
----


<source lang='javascript'>
'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++];
}
</source>
<source lang='javascript'>
<source lang='javascript'>
function isPositive(a) {
function isPositive(a) {
16번째 줄: 41번째 줄:
}
}
</source>
</source>
 
<source lang='javascript'>
==같이 보기==
function main() {
* [[해커랭크 10 Days of Javascript]]
    const n = +(readLine());
 
   
[[분류: 10 Days of Javascript]]
    for (let i = 0; i < n; i++) {
        const a = +(readLine());
     
        try {
            console.log(isPositive(a));
        } catch (e) {
            console.log(e.message);
        }
    }
}
</source>

2018년 8월 12일 (일) 15:02 판

개요

JS10 Day 3: Throw
해커랭크 10 Days of Javascript
# 문제 비고
2-3 Day e
6 JS10 Day 2: Conditional Statements: If-Else
7 JS10 Day 2: Conditional Statements: Switch
8 JS10 Day 2: Loops
9 JS10 Day 3: Arrays
10 JS10 Day 3: Try, Catch, and Finally
11 JS10 Day 3: Throw

'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 isPositive(a) {
    if( a == 0 ) return "Zero Error";
    if( a < 0 ) return "Negative Error";
    return "YES";
}
function main() {
    const n = +(readLine());
    
    for (let i = 0; i < n; i++) {
        const a = +(readLine());
      
        try {
            console.log(isPositive(a));
        } catch (e) {
            console.log(e.message);
        }
    }
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}