├── 2darray.js ├── 4function.js ├── addarray.js ├── adjacentmulti.js ├── assig.js ├── bookstatus.js ├── classarea.js ├── constfun.js ├── dateswitch.js ├── descending.js ├── evencount.js ├── function.js ├── grade.js ├── gradescore.js ├── incometax.js ├── mark.js ├── multiplication.js ├── myfilter.js ├── numpattern2.js ├── numtrianlge.js ├── oops2d.js ├── package-lock.json ├── package.json ├── palindrome.js ├── primecheck.js ├── reverse.js ├── sumofodd.js ├── swaparray.js └── throwerr.js /2darray.js: -------------------------------------------------------------------------------- 1 | var twod = require('readline-sync') 2 | 3 | var limit = twod.question('Enter the size of Array') 4 | var array1 = [] 5 | var array2 = [] 6 | var sumarray = [] 7 | 8 | console.log('Enter the values to Array 1') 9 | for (var i = 0; i < limit; i++) { 10 | array1[i] = [] 11 | for (var j = 0; j < limit; j++) { 12 | array1[i][j] = twod.question() 13 | } 14 | }console.log(array1) 15 | console.log('Enter the values of Array 2') 16 | for (var i = 0; i < limit; i++) { 17 | array2[i] = [] 18 | for (var j = 0; j < limit; j++) { 19 | array2[i][j] = twod.question() 20 | } 21 | }console.log(array2) 22 | console.log('Sum of 2 Arrays') 23 | for (var i = 0; i < limit; i++) { 24 | sumarray[i] = [] 25 | for (var j = 0; j < limit; j++) { 26 | sumarray[i][j] = parseInt(array1[i][j]) + parseInt(array2[i][j]) 27 | } 28 | }console.log(sumarray) 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /4function.js: -------------------------------------------------------------------------------- 1 | 2 | let someText = require("readline-sync") 3 | 4 | console.log("choose 1 for addition.") 5 | console.log("choose 2 for subtraction.") 6 | console.log("choose 3 for multiplication.") 7 | console.log("choose 4 for division.") 8 | 9 | let userSelect = someText.question("Enter your choice: ") 10 | // let input = parseInt(userSelect) 11 | 12 | switch(userSelect) { 13 | case 1: 14 | addition() 15 | break 16 | case 2: 17 | subtraction() 18 | break 19 | case 3: 20 | multiplication() 21 | break 22 | case 4: 23 | division() 24 | break 25 | default: 26 | console.log("Wrong choice.") 27 | break 28 | } 29 | 30 | 31 | 32 | function addition () { 33 | let num1 = someText.question("Enter number 1: ") 34 | let num2 = someText.question("Enter number 2: ") 35 | let result = num1 + num2 36 | console.log ("The sum of " + result ) 37 | } 38 | function subtraction () { 39 | let num1 = someText.question("Enter number 1: ") 40 | let num2 = someText.question("Enter number 2: ") 41 | let result = num1 - num2 42 | console.log ("The sum of " + result ) 43 | } 44 | function multiplication () { 45 | let num1 = someText.question("Enter number 1: ") 46 | let num2 = someText.question("Enter number 2: ") 47 | let result = num1 * num2 48 | console.log ("The sum of " + result ) 49 | } 50 | function division () { 51 | let num1 = someText.question("Enter number 1: ") 52 | let num2 = someText.question("Enter number 2: ") 53 | let result = num1 / num2 54 | console.log ("The sum of " + result ) 55 | } -------------------------------------------------------------------------------- /addarray.js: -------------------------------------------------------------------------------- 1 | let someText = require("readline-sync") 2 | let userIn = someText.question("Enter the size of array: ") 3 | let size = parseInt(userIn) 4 | let array1 = [], array2 = [], sumArray= []; 5 | 6 | for (let i = 0; i < size; i++) { 7 | array1[i] = [] 8 | array2[i] = [] 9 | sumArray[i] = [] 10 | } 11 | 12 | getArray(array1, array2, size) 13 | addArray(array1, array2, size, sumArray) 14 | displayArray(sumArray,size) 15 | 16 | function getArray(array1, array2, size) { 17 | console.log("Enter elements to array 1: ") 18 | for (let i = 0; i < size; i++) { 19 | for (let j = 0; j < size; j++) { 20 | array1[i][j] = someText.question("Enter element (" + i + ", " + j + "): ") 21 | } 22 | } 23 | console.log("Enter elements to array 2: ") 24 | for (let i = 0; i < size; i++) { 25 | for (let j = 0; j < size; j++) { 26 | array2[i][j] = someText.question("Enter element (" + i + ", " + j + "): ") 27 | } 28 | } 29 | } 30 | 31 | 32 | function addArray(array1, array2, size, sumArray) { 33 | for (let i = 0; i < size; i++) { 34 | for (let j = 0; j < size; j++) { 35 | sumArray[i][j] = parseInt(array1[i][j]) + parseInt(array2[i][j]) 36 | } 37 | } 38 | } 39 | 40 | function displayArray(sumArray, size) { 41 | console.log("Sum of array 1 and array 2 is : ") 42 | for (let i = 0; i < size; i++) { 43 | for(let j = 0; j < size; j++) { 44 | process.stdout.write(sumArray[i][j] + " ") 45 | } 46 | } 47 | } 48 | console.log() -------------------------------------------------------------------------------- /adjacentmulti.js: -------------------------------------------------------------------------------- 1 | let someText = require("readline-sync") 2 | let userIn = someText.question("Enter the array limit: ") 3 | let limit = parseInt(userIn) 4 | 5 | let arrayIn = new Array(limit) 6 | let arrayOut = new Array(limit - 1) 7 | 8 | console.log("Enter the elements to array: ") 9 | for (let i = 0; i < limit; i++) { 10 | arrayIn[i] = someText.question("Enter element " + i + ": ") 11 | } 12 | 13 | for (let i = 0; i < limit - 1; i++) { 14 | arrayOut[i] = parseInt(arrayIn[i]) * parseInt(arrayIn[i + 1]) 15 | } 16 | 17 | console.log("The output array is: ") 18 | for (let i = 0; i < limit - 1; i++) { 19 | process.stdout.write(arrayOut[i] + " ") 20 | } -------------------------------------------------------------------------------- /assig.js: -------------------------------------------------------------------------------- 1 | var read=require('readline-sync') 2 | 3 | var P=parseInt(read.question('Enter Prime amount')) 4 | var R=parseFloat (read.question('Enter Interest Rate')) 5 | var n=parseFloat(read.question('Enter the number of Years')) 6 | var SI=(P*R*n)/100 7 | 8 | console.log(SI) -------------------------------------------------------------------------------- /bookstatus.js: -------------------------------------------------------------------------------- 1 | var library = [ 2 | { 3 | title: 'Bill Gates', 4 | author: 'The Road Ahead', 5 | readingStatus: true 6 | }, 7 | 8 | { 9 | title: 'Steve Jobs', 10 | author: 'Walter Isaacson', 11 | readingStatus: true 12 | }, 13 | 14 | { 15 | title: 'Mockingjay: The Final Book of The Hunger Games', 16 | author: 'Suzanne Collins', 17 | readingStatus: false 18 | } 19 | ] 20 | 21 | const book = require("readline-sync") 22 | var option = book.question("Enter a option 1, 2, 3: ") 23 | 24 | if(option == 1){ 25 | if(library[0].readingStatus){ 26 | console.log(`Alredy read '${library[0].title}' by '${library[0].author}'`); 27 | }else{ 28 | console.log(`You still need to read '${library[0].title}' by '${library[0].author}'`); 29 | } 30 | } 31 | 32 | if(option == 2){ 33 | if(library[1].readingStatus){ 34 | console.log(`Alredy read '${library[1].title}' by '${library[1].author}'`); 35 | }else{ 36 | console.log(`You still need to read '${library[1].title}' by '${library[1].author}'`); 37 | } 38 | } 39 | 40 | if(option == 3){ 41 | if(library[2].readingStatus){ 42 | console.log(`Alredy read '${library[2].title}' by '${library[2].author}'`); 43 | }else{ 44 | console.log(`You still need to read '${library[2].title}' by '${library[2].author}'`); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /classarea.js: -------------------------------------------------------------------------------- 1 | class Area { 2 | circle(radius) { 3 | let area = 3.14 * radius * radius 4 | console.log("The area for the given circle with radius " + radius + " is: " + area) 5 | } 6 | 7 | square(side) { 8 | let area = side * side 9 | console.log("The area for the given square with side " + side + " is: " + area) 10 | } 11 | 12 | rectangle(length, breadth) { 13 | let area = length * breadth 14 | console.log("The area for the given rectangle with length " + length + " and breadth " + breadth + " is: " + area) 15 | } 16 | 17 | triangle(base, height) { 18 | let area = 0.5 * base * height 19 | console.log("The area for the given triangle with base " + base + " and height " + height + " is: " + area) 20 | 21 | } 22 | } 23 | 24 | class MyClass extends Area { 25 | 26 | circle() { 27 | let someText = require("readline-sync") 28 | let userIn = someText.question("Enter the radius for circle: ") 29 | let radius = parseInt(userIn) 30 | return radius 31 | } 32 | 33 | square() { 34 | let someText = require("readline-sync") 35 | let userIn = someText.question("Enter the side for the square: ") 36 | let side = parseInt(userIn) 37 | return side 38 | } 39 | 40 | rectangle() { 41 | let someText = require("readline-sync") 42 | let userInLength = someText.question("Enter the length of the rectangle: ") 43 | let userInBreadth = someText.question("Enter the breadth of the rectangle: ") 44 | let length = parseInt(userInLength) 45 | let breadth = parseInt(userInBreadth) 46 | return [length, breadth] 47 | } 48 | 49 | triangle() { 50 | let someText = require("readline-sync") 51 | let userInBase = someText.question("Enter the base of triangele: ") 52 | let userInHeight = someText.question("Enter the height of triangle: ") 53 | let base = parseInt(userInBase) 54 | let height = parseInt(userInHeight) 55 | return [base, height] 56 | } 57 | 58 | constructor (choice) { 59 | super() 60 | switch (choice) { 61 | case 1: 62 | console.log("You have chosen circle.") 63 | let radius = (this.circle()) 64 | super.circle(radius) 65 | break 66 | case 2: 67 | console.log("You have chosen square.") 68 | let side = (this.square()) 69 | super.square(side) 70 | break 71 | case 3: 72 | console.log("You have chosen rectangle.") 73 | const [length, breadth] = (this.rectangle()) 74 | super.rectangle(length, breadth) 75 | break 76 | case 4: 77 | console.log("You have chosen triangle.") 78 | const [base, height] = (this.triangle()) 79 | super.triangle(base, height) 80 | break 81 | default: 82 | console.log("Wrong choice.") 83 | } 84 | } 85 | } 86 | 87 | let someText = require("readline-sync") 88 | console.log("Enter 1 for Circle") 89 | console.log("Enter 2 for square") 90 | console.log("Enter 3 for rectangle") 91 | console.log("Enter 4 for triangle") 92 | let userIn = someText.question("Enter your choice: ") 93 | let choice = parseInt(userIn) 94 | 95 | const object = new MyClass(choice) 96 | -------------------------------------------------------------------------------- /constfun.js: -------------------------------------------------------------------------------- 1 | class Car { 2 | constructor(name, mileage, max_speed) { 3 | this.name = name; 4 | this.mileage = mileage; 5 | this.max_speed = max_speed; 6 | } 7 | } 8 | 9 | let maruthi = new Car("swift", 20, 120); 10 | console.log(maruthi); -------------------------------------------------------------------------------- /dateswitch.js: -------------------------------------------------------------------------------- 1 | var date=require('readline-sync') 2 | 3 | var choice=date.question('Select : 1 For Sunday\n 2 for Monday\n 3 for Tuesday\n 4 for Wednesday\n 5 for Thursday\n 6 for Friday\n 7 for Saturday') 4 | switch(choice){ 5 | case "1": 6 | console.log('You have selected Sunday') 7 | break; 8 | case "2": 9 | console.log('You have selected Monday') 10 | break; 11 | case "3": 12 | console.log('You have selected Tuesday') 13 | break; 14 | case "4": 15 | console.log('You have selected Wednesday') 16 | break; 17 | case "5": 18 | console.log('You have selected Thursday') 19 | break; 20 | case "6": 21 | console.log('You have selected Friday') 22 | break; 23 | case "7": 24 | console.log('You have selected Saturday') 25 | break; 26 | default: 27 | console.log('Invalid Entry') 28 | } -------------------------------------------------------------------------------- /descending.js: -------------------------------------------------------------------------------- 1 | var descend=require('readline-sync') 2 | var limit=descend.question('Enter the limit') 3 | 4 | var array=[] 5 | 6 | console.log('Enter values to an Array') 7 | for(k=0;k=90){ 6 | console.log('Grade A') 7 | }else if(mark>=80 && mark<=89){ 8 | console.log('Grade B') 9 | }else if( mark>=70 && mark<=79){ 10 | console.log('Grade C') 11 | }else if(mark>=60 && mark<=69){ 12 | console.log('Grade D') 13 | }else if(mark>=50 && mark<=59){ 14 | console.log('Grade E') 15 | }else{ 16 | console.log('Failed') 17 | } 18 | 19 | -------------------------------------------------------------------------------- /gradescore.js: -------------------------------------------------------------------------------- 1 | let someText = require("readline-sync") 2 | console.log("Enter the marks scored by the student: ") 3 | let writtenIn = someText.question("Written test: ") 4 | let writtenMark = parseInt(writtenIn) 5 | let labIn = someText.question("Lab exams: ") 6 | let labMark = parseInt(labIn) 7 | let assignmentsIn = someText.question("Assignment marks: ") 8 | let assignmentMark = parseInt(assignmentsIn) 9 | 10 | let grade = ((writtenMark * 70) / 100) + ((labMark * 20) / 100) + ((assignmentMark * 10) / 100) 11 | 12 | console.log("Grade of the student is: " + grade + ".") -------------------------------------------------------------------------------- /incometax.js: -------------------------------------------------------------------------------- 1 | let someText = require("readline-sync") 2 | let incomeIn = someText.question("Enter the annual income: ") 3 | let income = parseInt(incomeIn) 4 | 5 | if (income < 250000 ) { 6 | console.log("No tax to be paid.") 7 | } else if (250000 <= income < 500000) { 8 | let tax = (5 * income) / 100 9 | console.log("Income tax amount: " + tax + ".") 10 | } else if (500000 <= income < 1000000) { 11 | let tax = (20 * income) / 100 12 | console.log("Income tax amount: " + tax + ".") 13 | } else if (1000000 <= income < 5000000) { 14 | let tax = (30 * income) / 100 15 | console.log("Income tax amount: " + tax + ".") 16 | } -------------------------------------------------------------------------------- /mark.js: -------------------------------------------------------------------------------- 1 | var mark=require('readline-sync') 2 | 3 | var m=mark.question('Enter the mark in 100') 4 | 5 | if(m>=50){ 6 | console.log('You have passed') 7 | }else{ 8 | console.log('You have failed') 9 | } 10 | 11 | -------------------------------------------------------------------------------- /multiplication.js: -------------------------------------------------------------------------------- 1 | var multiply=require('readline-sync') 2 | 3 | var num=multiply.question('Eneter the number you want to get multiplication table') 4 | 5 | for(var i=1;i<=10;i++){ 6 | multi=i*num 7 | 8 | console.log(i+'x'+num+'='+multi) 9 | } -------------------------------------------------------------------------------- /myfilter.js: -------------------------------------------------------------------------------- 1 | const filter = require("readline-sync") 2 | 3 | var myArray=[1,2,3,4,5] 4 | var s = 0 5 | 6 | function myFilter(a, b){ 7 | 8 | console.log("sum is "+s) 9 | console.log(b) 10 | } 11 | function callback(a) 12 | { 13 | 14 | for(let i=0;i= 0.8.0" 17 | } 18 | } 19 | }, 20 | "dependencies": { 21 | "readline-sync": { 22 | "version": "1.4.10", 23 | "resolved": "https://registry.npmjs.org/readline-sync/-/readline-sync-1.4.10.tgz", 24 | "integrity": "sha512-gNva8/6UAe8QYepIQH/jQ2qn91Qj0B9sYjMBBs3QOB8F2CXcKgLxQaJRP76sWVRQt+QU+8fAkCbCvjjMFu7Ycw==" 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "readline-sync": "^1.4.10" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /palindrome.js: -------------------------------------------------------------------------------- 1 | var palindrome=require('readline-sync') 2 | 3 | console.log('Enter a word') 4 | var word=palindrome.question() 5 | 6 | var flag=0 7 | var len=word.length 8 | for(i=0;i= 200 ) 7 | throw "hugeHeightError"; 8 | else if(( isNaN(height ))) 9 | throw "not a number"; 10 | else if( height <= 40 ) 11 | throw "tinyHeightError"; 12 | else 13 | throw "Valid"; 14 | } 15 | 16 | catch(err){ 17 | console.log(err) 18 | } 19 | 20 | console.log("height is "+height) --------------------------------------------------------------------------------