Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Igaurav31 authored Oct 1, 2023
1 parent 6134598 commit 2237796
Show file tree
Hide file tree
Showing 6 changed files with 3,333 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Calculator-using-JS/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Calculator-using-JS
My first backend project
20 changes: 20 additions & 0 deletions Calculator-using-JS/bmiCalculator.html
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>
33 changes: 33 additions & 0 deletions Calculator-using-JS/calculator.js
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");
});
19 changes: 19 additions & 0 deletions Calculator-using-JS/index.html
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>
Loading

0 comments on commit 2237796

Please sign in to comment.