Skip to content

Commit

Permalink
check for input values
Browse files Browse the repository at this point in the history
  • Loading branch information
sarry7045 committed Oct 31, 2024
1 parent 01a9840 commit e5315b2
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
44 changes: 44 additions & 0 deletions check.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@


document.getElementById('angle').addEventListener('input', function () {
const angleInput = this;
const angleValue = parseFloat(angleInput.value);



if (angleValue < 0 || angleValue > 90) {
angleInput.setCustomValidity("Please enter a value between 0 and 90 degrees.");
} else {
angleInput.setCustomValidity("");
}

angleInput.reportValidity();
});

document.getElementById('mass').addEventListener('input', function () {
const massInput = this;
const massValue = parseFloat(massInput.value);

if (massValue < 0.1) {
massInput.setCustomValidity("Please enter a mass of at least 0.1 kg.");
} else {
massInput.setCustomValidity("");
}

massInput.reportValidity();
});


document.getElementById('force').addEventListener('input', function () {
const forceInput = this;
const forceValue = parseFloat(forceInput.value);

if (forceValue < 1) {
forceInput.setCustomValidity("Please enter a force of at least 1 Newton.");
} else {
forceInput.setCustomValidity("");
}

forceInput.reportValidity();
});

1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ <h3>Range</h3>
</div>
</div>
</div>
<script src="check.js"></script>
<script src="./projectile.js"></script>
<script src="./visulize.js"></script>
<script src="./script.js"></script>
Expand Down

0 comments on commit e5315b2

Please sign in to comment.