mirror of
https://github.com/ossu/computer-science.git
synced 2025-08-06 05:14:27 -04:00
Verify if a integer number is even or odd - refactor
This commit is contained in:
parent
c39d05f928
commit
336d92edc4
1 changed files with 40 additions and 38 deletions
|
@ -8,47 +8,49 @@ var prompt = require( 'prompt' );
|
||||||
// x *= x; // or x = x * x;
|
// x *= x; // or x = x * x;
|
||||||
// console.log( 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
|
// // 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:' );
|
// console.log( results.number );
|
||||||
// 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();
|
|
||||||
|
|
||||||
// });
|
// });
|
||||||
|
|
||||||
|
// 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
|
// // Find the lowest of three numbers
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue