Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function main() {
- var prompt = require('prompt');
- function gcd(a,b) {
- return ((b==0) ? a : gcd(b,a%b));
- }
- prompt.start()
- prompt.get(['a','b'], function(err,result) {
- try {
- var input = {
- 'a' : parseInt(result.a),
- 'b' : parseInt(result.b)
- }
- var errors = (function() {
- for (var i in input) {
- if (isNaN(input[i])) {
- throw new Error('The value entered for '+i+' is not a number!')
- }
- }
- return false;
- })();
- console.log('GCD is: '+gcd(input['a'],input['b']));
- } catch(err) {
- console.log("Had an error parsing your input: "+err);
- }
- });
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement