diff --git a/check.js b/check.js index d7a8dc9..661ab84 100644 --- a/check.js +++ b/check.js @@ -1,11 +1,11 @@ -// Select the input elements and the launch button +//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 to validate inputs + function validateInputs() { const mass = parseFloat(massInput.value); const velocity = parseFloat(velocityInput.value); @@ -14,7 +14,7 @@ function validateInputs() { let errors = []; - // Check each condition and add messages for any errors found + if (mass <= 0) { errors.push("Mass must be greater than 0."); } @@ -28,7 +28,6 @@ function validateInputs() { 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; @@ -36,10 +35,10 @@ function validateInputs() { 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(); }); diff --git a/script.js b/script.js index 3f26eb3..65d594b 100644 --- a/script.js +++ b/script.js @@ -1,6 +1,6 @@ const canvas = document.getElementById('canvas'); const ctx = canvas.getContext('2d'); -const g = 9.81; // Acceleration due to gravity (m/s²) +const g = 9.81; let animationId = null; let trajectory = []; @@ -11,7 +11,7 @@ class Projectile { constructor(mass, velocity, angle, height) { this.mass = mass; this.v0 = velocity; - this.angle = angle * Math.PI / 180; // Convert to radians + this.angle = angle * Math.PI / 180; this.h0 = height; this.x = 0; this.y = height; @@ -95,7 +95,7 @@ function animate() { const dt = 0.016; // 60 FPS projectile.update(dt); - // Scale factors for drawing + // Scale const scaleX = canvas.width / (projectile.range + 10); const scaleY = canvas.height / (projectile.maxHeight + 10); const scale = Math.min(scaleX, scaleY);