Advertisement
Guest User

Untitled

a guest
Sep 26th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function main() {
  2.   var prompt = require('prompt');
  3.  
  4.   function gcd(a,b) {
  5.     return ((b==0) ? a : gcd(b,a%b));
  6.   }
  7.  
  8.   prompt.start()
  9.  
  10.   prompt.get(['a','b'], function(err,result) {
  11.     try {
  12.  
  13.       var input = {
  14.         'a' : parseInt(result.a),
  15.         'b' : parseInt(result.b)
  16.       }
  17.  
  18.       var errors = (function() {
  19.         for (var i in input) {
  20.           if (isNaN(input[i])) {
  21.             throw new Error('The value entered for '+i+' is not a number!')
  22.           }
  23.         }
  24.         return false;
  25.       })();
  26.  
  27.       console.log('GCD is: '+gcd(input['a'],input['b']));
  28.  
  29.     } catch(err) {
  30.       console.log("Had an error parsing your input: "+err);
  31.     }
  32.   });
  33. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement