-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck.js
50 lines (40 loc) · 1.29 KB
/
check.js
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
//check the value
const massInput = document.getElementById("mass");
const velocityInput = document.getElementById("velocity");
const angleInput = document.getElementById("angle");
const heightInput = document.getElementById("height");
const launchButton = document.getElementById("launch");
function validateInputs() {
const mass = parseFloat(massInput.value);
const velocity = parseFloat(velocityInput.value);
const angle = parseFloat(angleInput.value);
const height = parseFloat(heightInput.value);
let errors = [];
if (mass <= 0) {
errors.push("Mass must be greater than 0.");
}
if (velocity <= 0) {
errors.push("Initial Velocity must be greater than 0.");
}
if (angle > 90) {
errors.push("Angle must not be greater than 90 degrees.");
}
if (height > 100) {
errors.push("Initial Height must not be more than 100 meters.");
}
if (errors.length > 0) {
alert(errors.join("\n"));
return false;
}
return true;
}
launchButton.addEventListener("click", (e) => {
if (validateInputs()) {
import('./script.js').then(module => {
module.launchSimulation();
});
}
});
export function launchSimulation() {
console.log("Simulation launched with valid inputs!");
}