-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 6cd8b6c
Showing
5 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)*/ |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |