mirror of
https://github.com/ossu/computer-science.git
synced 2024-12-27 00:09:32 -05:00
Intro to CS MIT -> Lecture 02 - even and odd number
This commit is contained in:
parent
b504a25d24
commit
4a8585e6b8
@ -3,8 +3,8 @@
|
||||
## Unit 1
|
||||
|
||||
- INTRODUCTION TO 6.00 ✔
|
||||
- CORE ELEMENTS OF A PROGRAM ✍
|
||||
- PROBLEM SOLVING
|
||||
- CORE ELEMENTS OF A PROGRAM ✔
|
||||
- PROBLEM SOLVING ✍
|
||||
- MACHINE INTERPRETATION OF A PROGRAM
|
||||
- OBJECTS IN PYTHON
|
||||
- RECURSION
|
||||
|
@ -0,0 +1,53 @@
|
||||
//// Create a variable x and assign value 3 to it
|
||||
//var x = 3;
|
||||
//
|
||||
//// Bind x to value 9
|
||||
//x *= x; // or x = x * x;
|
||||
//console.log( x );
|
||||
|
||||
//// read input data from terminal
|
||||
//process.stdin.resume();
|
||||
//
|
||||
//console.log( 'Enter a number:' );
|
||||
//process.stdin.setEncoding( 'utf8' );
|
||||
//
|
||||
//process.stdin.on( 'data', function( input ) {
|
||||
//
|
||||
// console.log( typeof( input ));
|
||||
// console.log( input );
|
||||
//
|
||||
// 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
|
||||
process.stdin.resume();
|
||||
|
||||
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();
|
||||
|
||||
});
|
Loading…
Reference in New Issue
Block a user