Verify if a integer number is even or odd - refactor

This commit is contained in:
ericdouglas 2015-06-01 11:55:19 -03:00
parent c39d05f928
commit 336d92edc4

View File

@ -8,47 +8,49 @@ var prompt = require( 'prompt' );
// x *= x; // or x = x * x;
// console.log( x );
// read input data from terminal
prompt.start();
prompt.get({
name : 'number',
description : 'Enter a number'
}, function( err, results ) {
console.log( results.number );
});
// // Verify if a integer number is even or odd.
// // If odd, verify if the number is divisible by 3
// // read input data from terminal
// process.stdin.resume();
// prompt.start();
// prompt.get({
// name : 'number',
// description : 'Enter a number'
// }, function( err, results ) {
// console.log( 'Enter a integer:' );
// process.stdin.setEncoding( 'utf8' );
// process.stdin.on( 'data', function( input ) {
// var int = parseInt( input, 10 );
// if ( int % 2 === 0 ) {
// console.log( 'Even' );
// } else {
// console.log( 'Odd' );
// if ( int % 3 !== 0 ) {
// console.log( 'And not divisible by 3' );
// }
// }
// process.exit();
// console.log( results.number );
// });
// 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 of three numbers