-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalcScripts.js
More file actions
58 lines (38 loc) · 1.79 KB
/
Copy pathcalcScripts.js
File metadata and controls
58 lines (38 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
function getOption() {
selectElement = document.querySelector('.selectOption');
output = selectElement.value;
document.querySelector('.output').textContent = output;
}
function waterIntake() {
let userWeight = parseFloat(prompt("Please enter your body weight:"));
while (isNaN(userWeight) || userWeight <= 0 || userWeight > 1500) {
userWeight = parseFloat(prompt("Invalid input. Please enter a valid body weight:"));
}
const waterRec = userWeight * 0.5;
console.log("Valid weight entered:", userWeight);
console.log("Recommended water intake (in ml):", waterRec);
document.querySelector('#waterCalculator').innerText = "Recommended water intake: " + waterRec + " oz";
}
function requiredCalories() {
let userGender = prompt("Please enter your gender (male/female):").toLowerCase();
while (userGender !== "male" && userGender !== "female") {
userGender = prompt("Invalid input. Please enter your gender (male/female):").toLowerCase();
}
// Continue with the rest of your function here
console.log(userGender);
}
function foodCal() {
let selectElement = document.querySelector('#gender');
let userGender = selectElement.value;
let userWeight = parseFloat(prompt("Please enter your body weight (lbs)"));
while (isNaN(userWeight) || userWeight <= 0 || userWeight > 1500) {
userWeight = parseFloat(prompt("Invalid input. Please enter a valid body weight:"));
}
let recCal;
if (userGender === "male") {
recCal = 900 + 10 * (userWeight * 0.453592);
} else {
recCal = 800 + 7 * (userWeight * 0.453592);
}
document.querySelector("#calorieOutput").innerText = "Recommended Calorie Intake: " + Math.round(recCal) + " kcal";
}