Skip to content
Permalink
1202abe436
Go to file
 
 
Cannot retrieve contributors at this time
76 lines (76 sloc) 2.14 KB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Chapter 3 Exercises</title>
</head>
<body>
<div class="minimum">
<h1>Minimum Function</h1>
<pre>
<code>
function min(num1, num2) {
return num1 < num2 ? num1 : num2
}
</code>
</pre>
<input type="number" name="num1" id="num1" value="0">
<input type="number" name="num2" id="num2" value="0">
<div>Minimum: <span id="minOutput"></span></div>
</div>
<div class="recursion">
<h1>Recursion</h1>
<pre>
<code>
function isEven(num) {
num < 0 ? num *= -1 : num
if (num == 0) return true
else if (num == 1) return false
else return isEven(num - 2)
}
</code>
</pre>
<input type="number" name="recursion" id="isEven" value="0">
<div>Is Even?: <span id="evenOutput"></span></div>
</div>
<div class="bean">
<h1>Bean Counting</h1>
<pre>
<code>
function countBs(beanString) {
let count = 0
for (let i = 0; i < beanString.length; i++) {
const element = beanString[i];
if (element === 'B') count++;
}
return count
}
</code>
</pre>
<input type="text" name="bean" id="beanInput" placeholder="String to search">
<div><span id="beanOutput"></span> B's</div>
</div>
<div class="char">
<h1>Char Counting</h1>
<pre>
<code>
function countChar(string, char) {
let count = 0;
for (let i = 0; i < string.length; i++) {
const element = string[i];
if (element === char) count++;
}
return count;
}
</code>
</pre>
<input type="text" name="charInput" id="charInput" placeholder="String to search">
<input type="text" name="inputChar" id="inputChar" placeholder="Character to look for" maxlength="1">
<div><span id="charOutput"></span> <span id="charSearch"></span>'s</div>
</div>
<script src="minimum.js"></script>
<script src="recursion.js"></script>
<script src="bean.js"></script>
</body>
</html>
You can’t perform that action at this time.