Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
<li class="nav-item">
<a class="nav-link" href="task5.html">Task5</a>
</li>
<li class="nav-item">
<a class="nav-link" href="task6.html">Task6</a>
</li>
</ul>
</div>
</div>
Expand Down
25 changes: 25 additions & 0 deletions js/complexTemp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
function clothesCheckWithLogicalOperator() {
var temperature;
var dressAdvice;
temperature = document.getElementById('temperature').value;
if (temperature == "") {
return;
}

// All dropdown values are valid numerics so not validating here.
var tempC = parseInt(temperature);
var dressAdvice;

// This is a bit more complex than the Task5 solution, but
// the checks can be in any order - hence I've moved them around.
if (tempC >= 50)
dressAdvice = 'Pants and Vest are fine';
else if (tempC < 0)
dressAdvice = 'Stay Inside';
else if (tempC < 30 && tempC >= 0)
dressAdvice = 'Wear a Coat and a Hat';
else if (tempC < 50 && tempC >= 30)
dressAdvice = 'Wear a Coat';

document.getElementById('dressSense').innerHTML = dressAdvice;
}
3 changes: 2 additions & 1 deletion js/moreTemp.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ function clothesCheck() {
var tempC = parseInt(temperature);
var dressAdvice;

// The Zen of Python point 5: Flat is better than nested...
// This is a simple solution, but it depends on the tests being in
// the correct sequence.
if (tempC >= 50)
dressAdvice = 'Pants and Vest are fine';
else if (tempC >= 30)
Expand Down
3 changes: 3 additions & 0 deletions task1.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
<li class="nav-item">
<a class="nav-link" href="task5.html">Task5</a>
</li>
<li class="nav-item">
<a class="nav-link" href="task6.html">Task6</a>
</li>
</ul>
</div>

Expand Down
3 changes: 3 additions & 0 deletions task2.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
<li class="nav-item">
<a class="nav-link" href="task5.html">Task5</a>
</li>
<li class="nav-item">
<a class="nav-link" href="task6.html">Task6</a>
</li>
</ul>
</div>

Expand Down
3 changes: 3 additions & 0 deletions task3.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
<li class="nav-item">
<a class="nav-link" href="task5.html">Task5</a>
</li>
<li class="nav-item">
<a class="nav-link" href="task6.html">Task6</a>
</li>
</ul>
</div>

Expand Down
3 changes: 3 additions & 0 deletions task4.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
<li class="nav-item">
<a class="nav-link" href="task5.html">Task5</a>
</li>
<li class="nav-item">
<a class="nav-link" href="task6.html">Task6</a>
</li>
</ul>
</div>

Expand Down
6 changes: 5 additions & 1 deletion task5.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="task5.html">Task5</a>
</li>
<li class="nav-item">
<a class="nav-link" href="task6.html">Task6</a>
</li>
</ul>
</div>

Expand Down Expand Up @@ -141,7 +144,8 @@ <h1>Task 5</h1>
var tempC = parseInt(temperature);
var dressAdvice;

// The Zen of Python point 5: Flat is better than nested...
// This is a simple solution but it depends on the tests being in
// the correct sequence.
if (tempC >= 50)
dressAdvice = 'Pants and Vest are fine';
else if (tempC >= 30)
Expand Down
184 changes: 184 additions & 0 deletions task6.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
<!doctype html>
<html lang="en" class="bg-light">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Functions and Control Flow</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BmbxuPwQa2lc/FVzBcNJ7UAyJxM6wuqIj61tLrc4wSX0szH/Ev+nYRRuWlolflfl" crossorigin="anonymous">
<link rel="stylesheet" href="/css/index.css">
<script type="text/javascript" src="/js/complexTemp.js"></script>
</head>

<body class="bg-light">

<nav class="navbar navbar-expand-lg navbar-dark bg-secondary">
<div class="container-fluid">
<a class="navbar-brand text-warning" href="/">
<img src="/img/greywidget.jpg" alt="the author and his cat" width="48" height="48" class="d-inline-block align-top">
<span class="display-6">Functions and Control Flow</span>
</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="index.html">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="task1.html">Task1</a>
</li>
<li class="nav-item">
<a class="nav-link" href="task2.html">Task2</a>
</li>
<li class="nav-item">
<a class="nav-link" href="task3.html">Task3</a>
</li>
<li class="nav-item">
<a class="nav-link" href="task4.html">Task4</a>
</li>
<li class="nav-item">
<a class="nav-link" href="task5.html">Task5</a>
</li>
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="task6.html">Task6</a>
</li>
</ul>
</div>


</div>
</nav>

<!-- Main Container -->
<div class="container-fluid pb-5">

<main class="row justify-content-center pt-3 main-row">

<div class="row justify-content-between pb-3">
<div class="col-2">
<img src="/img/the_human.png" alt="the author in silhouette" class="d-block w-100">
</div>
<div class="col-2">
<img src="/img/the_cat.png" alt="the author's cat in silhouette" class="d-block w-100">
</div>
</div>

<div class="row justify-content-center pt-3">
<div class="col-sm-10">
<h1>Task 6</h1>
<p class="lead">This is the same as <strong>Task5</strong>, but we need to use a <em>Logical Operator</em>.
As a reminder - here are the requirements again:</p>
<ul>
<li>If it's less than 50 degrees, <em>wear a coat</em>.</li>
<li>If it's less than 30 degrees, <em>wear a coat and hat</em>.</li>
<li>If it's less than 0 degrees, <em>stay inside</em></li>
<li>Otherwise, <em>pants and vest are fine</em>.</li>
</ul>

<!-- start -->
<div class="row">
<div class="col-sm-6">
<form class='needs-validation' name='contact' novalidate><input type='hidden' name='form-name' value='contact' />
<div class="mb-3">
<label for="temperature" class="form-label">Temperature</label>
<select class="form-select" aria-label="select temperature" id="temperature" name="temperature" value="" required>
<option selected disabled value="">Please select the temperature</option>
<option value="-1">-1</option>
<option value="0">0</option>
<option value="25">25</option>
<option value="30">30</option>
<option value="40">40</option>
<option value="50">50</option>
<option value="55">55</option>
</select>
<div class="invalid-feedback">Please select the temperature</div>
</div>
<div class="d-grid">
<button class="btn btn-secondary text-warning" type="submit" onclick="clothesCheckWithLogicalOperator()">Submit</button>
</div>
</form>
<script>
// Example starter JavaScript for disabling form submissions if there are invalid fields
(function () {
'use strict'

// Fetch all the forms we want to apply custom Bootstrap validation styles to
var forms = document.querySelectorAll('.needs-validation')

// Loop over them and prevent submission
Array.prototype.slice.call(forms)
.forEach(function (form) {
form.addEventListener('submit', function (event) {
if (!form.checkValidity()) {
event.preventDefault()
event.stopPropagation()
}
// Force the page not to refresh, since there is no server and we just want the values
event.preventDefault()
event.stopPropagation()


form.classList.add('was-validated')
}, false)
})
})()
</script>
</div>
<div class="col-sm-6 text-center">
<p id="dressSense" class="text-danger pt-4 fs-4"></p>
</div>
</div>
<!-- end -->

<div class="bg-white mt-5">
<pre>
function clothesCheckWithLogicalOperator() {
var temperature;
var dressAdvice;
temperature = document.getElementById('temperature').value;
if (temperature == "") {
return;
}

// All dropdown values are valid numerics so not validating here.
var tempC = parseInt(temperature);
var dressAdvice;

// This is a bit more complex than the Task5 solution, but
// the checks can be in any order - hence I've moved them around.
if (tempC >= 50)
dressAdvice = 'Pants and Vest are fine';
else if (tempC < 0)
dressAdvice = 'Stay Inside';
else if (tempC < 30 && tempC >= 0)
dressAdvice = 'Wear a Coat and a Hat';
else if (tempC < 50 && tempC >= 30)
dressAdvice = 'Wear a Coat';

document.getElementById('dressSense').innerHTML = dressAdvice;
}</pre>
</div>
</div>
</div>
</main>

</div> <!-- main container div -->

<footer class="fixed-bottom py-3 bg-secondary text-warning">
<div class="container-fluid text-small">
<div class="row mt-auto">
<div class="col-4">
&copy; greywidget 2021.
</div>
<div class="col-8 text-end">
The cat is not responsible for the content of this site.
</div>
</div>
</div>
</footer>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta2/dist/js/bootstrap.bundle.min.js" integrity="sha384-b5kHyXgcpbZJO/tY9Ul7kGkf1S0CWuKcCD38l8YkeH8z8QjE0GmW1gYU5S9FOnJ0" crossorigin="anonymous"></script>

</body>
</html>