76 lines
2.5 KiB
HTML
76 lines
2.5 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Women4IT - JavaScript</title>
|
|
<meta name="description" content="Women4IT JavaScript Exercise: Variables -1">
|
|
<!-- Bootstrap CSS -->
|
|
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
|
|
<!-- Customise Bootstrap for practical grid layouts -->
|
|
<link rel="stylesheet" href="../assets/css/bootstrap-custom.css">
|
|
<style>
|
|
.container { padding-top: 40px }
|
|
.js-box {
|
|
border:solid 1px yellow;
|
|
padding:20px;
|
|
background-color: lightyellow;
|
|
margin-bottom: 48px;
|
|
font-size: larger;
|
|
}
|
|
#resultBox, #resultNum {
|
|
border: solid 1px green;
|
|
height: 40px;
|
|
background-color: #E7FFE7;
|
|
width: 280px;
|
|
padding: 3px 12px;
|
|
}
|
|
|
|
</style>
|
|
|
|
</head>
|
|
|
|
|
|
<body>
|
|
<div class="container col-md-8 offset-md-2">
|
|
<h1><b>Exercise 7-5</b>: Javascript Conditional Statements</h1>
|
|
<p>This script tests user input with the <i>if</i> and <i>else if</i> commands, and the || logical operator.</p>
|
|
|
|
<h3>Using <i>if</i> and <i>else if</i> statements with the || operator</h3>
|
|
<div class="js-box">
|
|
|
|
<script>
|
|
let userNumber;
|
|
userNumber = window.prompt("Please enter a number between 1 and 100.");
|
|
if ( (userNumber < 0 ) || (userNumber > 100 ) ) {
|
|
window.alert("Your entered number is not within the allowed range.");
|
|
}
|
|
else if (userNumber < 50 ) {
|
|
window.alert("Your entered number is less than 50.");
|
|
}
|
|
|
|
else if (userNumber > 50 ) {
|
|
window.alert("Your entered number is greater than 50.");
|
|
}
|
|
|
|
else if (userNumber == 50 ) {
|
|
window.alert("Your entered number is exactly 50.");
|
|
}
|
|
</script>
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<!-- jQuery library -->
|
|
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
|
|
<!-- Popper JS -->
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
|
|
<!-- Latest compiled JavaScript -->
|
|
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
|
|
</body>
|
|
</html> |