-
Notifications
You must be signed in to change notification settings - Fork 42
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
Showing
6 changed files
with
3,333 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,2 @@ | ||
# Calculator-using-JS | ||
My first backend project |
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,20 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>BMI Calculator</title> | ||
</head> | ||
<body> | ||
<h1>BMI Calculator</h1> | ||
<form action="/bmicalculator" method="post" > | ||
<input type="text" name="height" placeholder="Enter your height in meter"> | ||
<input type="text" name="weight" placeholder="Enter your weight in Kilogram"> | ||
<button type="submit">calculate BMI</button> | ||
</form> | ||
<br> | ||
Go back to <a href="http://localhost:3000/">home.</a> | ||
|
||
</body> | ||
</html> |
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,33 @@ | ||
const express = require("express"); | ||
const bodyParser = require("body-parser"); | ||
const app = express(); | ||
|
||
app.use(bodyParser.urlencoded({extended: true})); | ||
|
||
|
||
app.get("/", function(req, res){ | ||
res.sendFile(__dirname + "/index.html"); | ||
}); | ||
|
||
app.post("/", function(req, res){ | ||
var num1 = Number(req.body.no1); | ||
var num2 = Number(req.body.no2); | ||
var result = num1 + num2; | ||
|
||
res.send("The result is "+ result); | ||
}); | ||
|
||
app.get("/bmicalculator", function(req, res){ | ||
res.sendFile(__dirname + "/bmiCalculator.html"); | ||
}); | ||
|
||
app.post("/bmicalculator", function(req,res){ | ||
var h = parseFloat(req.body.height); | ||
var w = parseFloat(req.body.weight); | ||
var bmi = w/(h*h); | ||
res.send("Your BMI is: " + bmi); | ||
}); | ||
|
||
app.listen(3000, function(){ | ||
console.log("server created"); | ||
}); |
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,19 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Calculator</title> | ||
</head> | ||
<body> | ||
<h1>Calculator</h1> | ||
<form action="/" method="post"> | ||
<input type="text" placeholder="enter num 1" name="no1"> | ||
<input type="text" placeholder="enter num 2" name="no2"> | ||
<button type="submit">Calculate</button> | ||
</form> | ||
<br> | ||
To calculate BMI go <a href="http://localhost:3000/bmiCalculator">here.</a> | ||
</body> | ||
</html> |
Oops, something went wrong.