Find the lowest among three numbers

This commit is contained in:
ericdouglas 2015-06-01 12:06:06 -03:00
parent 336d92edc4
commit 7445229287

View File

@ -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' );
}
});