Skip to content

Commit

Permalink
Area
Browse files Browse the repository at this point in the history
  • Loading branch information
aramo2000 committed Nov 7, 2019
0 parents commit 6cd8b6c
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
22 changes: 22 additions & 0 deletions area.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
function squareArea(side) {
return side * side
}

function rectArea(length, width) {
return length * width
}

function circleArea(radius) {
return radius * radius * Math.PI
}

function triangleArea(height, base) {
return height * base / 2
}

module.exports = {
squareArea, //it's like "squareArea": squareArea,
rectArea,
circleArea,
triangleArea
}
42 changes: 42 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const reader = require('readline-sync')
const area = require("./area.js")

console.log("Supported Shapes:")
console.log("1: Circle 2: Rectange")
console.log("3: Square 4: Triangle")

const option = reader.questionInt("What is your choice? ")
let result;

switch(option) {
case 1:
const radius = reader.questionInt(" radius = ")
result = area.circleArea(radius)
break;
case 2:
const width = reader.questionInt(" width = ")
const length = reader.questionInt(" length = ")
result = area.rectArea(length, width)
break;
case 3:
const side = reader.questionInt(" side = ")
result = area.squareArea(side)
break;
case 4:
const height = reader.questionInt(" height = ")
const base = reader.questionInt(" base = ")
result = area.triangleArea(height, base)
break;
default:
console.log("Type not supported")
}

if(result) {
console.log("result = " + result)
} else {
console.log("Type not supported!")
}

/*const area = require("./area.js")
const result = area.rectArea(6, 2)
console.log("result is = " + result)*/
13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "area",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"readline-sync": "^1.4.10"
}
}

0 comments on commit 6cd8b6c

Please sign in to comment.