From 7445229287c6c5d0b6d42d32cbfc56bd261ef7f9 Mon Sep 17 00:00:00 2001 From: ericdouglas Date: Mon, 1 Jun 2015 12:06:06 -0300 Subject: [PATCH] Find the lowest among three numbers --- .../src/02-lecture.js | 83 +++++++++++++------ 1 file changed, 59 insertions(+), 24 deletions(-) diff --git a/computer-science/01-introduction-to-cs-and-programming-mit/src/02-lecture.js b/computer-science/01-introduction-to-cs-and-programming-mit/src/02-lecture.js index 15c2975..b247eaa 100644 --- a/computer-science/01-introduction-to-cs-and-programming-mit/src/02-lecture.js +++ b/computer-science/01-introduction-to-cs-and-programming-mit/src/02-lecture.js @@ -19,38 +19,73 @@ var prompt = require( 'prompt' ); // }); -// Verify if a integer number is even or odd. -// If odd, verify if the number is divisible by 3 -// read input data from terminal -prompt.start(); +// // Verify if a integer number is even or odd. +// // If odd, verify if the number is divisible by 3 +// // read input data from terminal +// prompt.start(); +// prompt.get([ +// { +// name : 'number', +// description : 'Enter a integer' +// } +// ], function( err, results ) { + +// var int = parseInt( results.number, 10 ); + +// if ( int % 2 === 0 ) { + +// console.log( int + ' is EVEN' ); + +// } else { + +// var msg = int.toString() + ' is ODD'; + +// if ( int % 3 !== 0 ) { + +// msg += ' and NOT divisible by 3'; + +// } + +// console.log( msg ); + +// } + +// }); + +// Find the lowest among three numbers +prompt.start(); prompt.get([ { - name : 'number', - description : 'Enter a integer' + name : 'x', + description : 'Enter x' + }, + { + name : 'y', + description : 'Enter y' + }, + { + name : 'z', + description : 'Enter z' } ], function( err, results ) { - var int = parseInt( results.number, 10 ); - - if ( int % 2 === 0 ) { - - console.log( int + ' is EVEN' ); + if ( results.x < results.y ) { + if ( results.x < results.z ) { + console.log( 'x is least' ); } else { - - var msg = int.toString() + ' is ODD'; - - if ( int % 3 !== 0 ) { - - msg += ' and NOT divisible by 3'; - - } - - console.log( msg ); - + console.log( 'z is least' ); } -}); + } else if ( results.y < results.z ) { -// // Find the lowest of three numbers + console.log( 'y is least' ); + + } else { + + console.log( 'z is least' ); + + } + +});