Skip to content

Commit 09eab42

Browse files
authored
Create Throw.js
1 parent 4d2c0fd commit 09eab42

File tree

1 file changed

+38
-0
lines changed
  • Hackerrank solutions/10 days of js

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
'use strict';
2+
3+
process.stdin.resume();
4+
process.stdin.setEncoding('utf-8');
5+
6+
let inputString = '';
7+
let currentLine = 0;
8+
9+
process.stdin.on('data', inputStdin => {
10+
inputString += inputStdin;
11+
});
12+
13+
process.stdin.on('end', _ => {
14+
inputString = inputString.trim().split('\n').map(string => {
15+
return string.trim();
16+
});
17+
18+
main();
19+
});
20+
21+
function readLine() {
22+
return inputString[currentLine++];
23+
}
24+
25+
/*
26+
* Complete the isPositive function.
27+
* If 'a' is positive, return "YES".
28+
* If 'a' is 0, throw an Error with the message "Zero Error"
29+
* If 'a' is negative, throw an Error with the message "Negative Error"
30+
*/
31+
function isPositive(a) {
32+
if (a === 0)
33+
throw Error('Zero Error');
34+
if (a < 0)
35+
throw Error('Negative Error');
36+
37+
return 'YES';
38+
}

0 commit comments

Comments
 (0)