The two problems that i think with the code are that its not saving the input values therefore the the code is not displaying any result and secondly from the dropdown list only first option gets selected everytime. Kindly let me know the errors in the code. I am new to coding.
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>Tip Calculator</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-0evHe/X+R7YkIZDRvuzKMRqM+OrBnVFBL6DOitfPri4tjfHxaWutUpFmBp4vmVor" crossorigin="anonymous">
<link rel="stylesheet" href="styles.css" />
</head>
<body>
<form>
<div class="mb-3">
<label class="total form-label">Total Bill</label>
<input type="number" class="form-control" id="bill" >
<div id="emailHelp" class="form-text">Please Enter your bill in numbers only.</div>
</div>
<div class="mb-3">
<label class="form-label">Number of People</label>
<input type="number" class="form-control" id="people">
</div>
<!-- <div class="mb-3 form-check">
<input type="checkbox" class="form-check-input" id="exampleCheck1">
<label class="form-check-label" for="exampleCheck1">Check me out</label>
</div> -->
<select class="form-select" id="myValues">
<option value="30%">Select the service quality</option>
<option value="30%">30% - Outstanding</option>
<option value="20%">20% - Good</option>
<option value="15%">15% - it was okay</option>
<option value="5%">5% - Terrible</option>
</select>
<button type="submit" class="btn btn-primary">Calculate</button>
</form>
<div id="totalTip">
<sup>$</sup><span class="form-label" id="tip">0.00</span>
<small id="each">each</small>
</div>
</body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script src="tip.js" charset="utf-8"></script>
</html>
This is the javascript code
var a = $("#bill").val();
var b = $("#people").val();
var c = $("#myValues").find('option:selected').val();
$(".btn").click(function () {
$("#tip").html(calculateTip(a, b, c));
});
function calculateTip (total, people, select) {
var d = total/people;
var e = d*(select/100);
return e;
}
// calculateTip(a, b, c)