From f3c915f41d57b068b441a3dc125312b8ca2cc24f Mon Sep 17 00:00:00 2001 From: Aditya Yadav <108022811+iamaaadddity7977@users.noreply.github.com> Date: Sat, 9 Nov 2024 17:16:36 +0000 Subject: [PATCH] add check file --- check.js | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ index.html | 1 + 2 files changed, 52 insertions(+) create mode 100644 check.js diff --git a/check.js b/check.js new file mode 100644 index 0000000..d7a8dc9 --- /dev/null +++ b/check.js @@ -0,0 +1,51 @@ +// Select the input elements and the launch button +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 to validate inputs +function validateInputs() { + const mass = parseFloat(massInput.value); + const velocity = parseFloat(velocityInput.value); + const angle = parseFloat(angleInput.value); + const height = parseFloat(heightInput.value); + + let errors = []; + + // Check each condition and add messages for any errors found + 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."); + } + + // Display errors or proceed with simulation + if (errors.length > 0) { + alert(errors.join("\n")); + return false; + } + return true; +} + +// Event listener for the launch button +launchButton.addEventListener("click", (e) => { + if (validateInputs()) { + // If inputs are valid, proceed with the simulation in `script.js` + import('./script.js').then(module => { + module.launchSimulation(); + }); + } +}); +export function launchSimulation() { + + console.log("Simulation launched with valid inputs!"); +} diff --git a/index.html b/index.html index 1e28fb4..ea5bc90 100644 --- a/index.html +++ b/index.html @@ -54,6 +54,7 @@

Final Velocity

+ \ No newline at end of file