-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripts1.js
More file actions
47 lines (40 loc) · 1.39 KB
/
scripts1.js
File metadata and controls
47 lines (40 loc) · 1.39 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
// Gravity Calculator
function calculateGravity() {
const weightOnEarth = document.getElementById('weightOnEarth').value;
if (!weightOnEarth) {
alert('Please enter your weight');
return;
}
const gravityFactors = {
Mercury: 0.38,
Venus: 0.91,
Earth: 1,
Mars: 0.38,
Jupiter: 2.34,
Saturn: 1.06,
Uranus: 0.92,
Neptune: 1.19
};
let result = 'Your weight on different planets: \n';
for (const planet in gravityFactors) {
const planetWeight = (weightOnEarth * gravityFactors[planet]).toFixed(2);
result += `${planet}: ${planetWeight} kg\n`;
}
document.getElementById('gravityResult').textContent = result;
}
// Distance Calculator
function calculateDistance() {
const distance = document.getElementById('destination').value;
document.getElementById('distanceResult').textContent = `Distance: ${distance} km`;
}
// Travel Time Estimator
function calculateTravelTime() {
const speed = document.getElementById('speed').value;
const distance = document.getElementById('destination').value;
if (!speed) {
alert('Please enter the speed');
return;
}
const time = (distance / speed).toFixed(2);
document.getElementById('travelTimeResult').textContent = `Estimated travel time: ${time} hours`;
}