From 4a8585e6b8abf7b5c5eb38c78043e694dcf01622 Mon Sep 17 00:00:00 2001 From: ericdouglas Date: Sun, 31 May 2015 14:27:37 -0300 Subject: [PATCH] Intro to CS MIT -> Lecture 02 - even and odd number --- .../README.md | 4 +- .../src/02-lecture.js | 53 +++++++++++++++++++ 2 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 computer-science/01-introduction-to-cs-and-programming-mit/src/02-lecture.js diff --git a/computer-science/01-introduction-to-cs-and-programming-mit/README.md b/computer-science/01-introduction-to-cs-and-programming-mit/README.md index 7a222d6..50508f6 100644 --- a/computer-science/01-introduction-to-cs-and-programming-mit/README.md +++ b/computer-science/01-introduction-to-cs-and-programming-mit/README.md @@ -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 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 new file mode 100644 index 0000000..862edae --- /dev/null +++ b/computer-science/01-introduction-to-cs-and-programming-mit/src/02-lecture.js @@ -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(); + +}); \ No newline at end of file