Skip to content
Open
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
20 changes: 10 additions & 10 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ <h1>Loops Exercises</h1>

<section id="menu">
<ul>
<li><button type="button" class="btn btn-primary" onclick="yourFunctionName()">Example 2.1</button></li>
<li><button type="button" class="btn btn-primary" onclick="yourFunctionName()">Example 2.2</button></li>
<li><button type="button" class="btn btn-primary" onclick="yourFunctionName()">Example 2.3</button></li>
<li><button type="button" class="btn btn-primary" onclick="yourFunctionName()">Example 2.4</button></li>
<li><button type="button" class="btn btn-primary" onclick="yourFunctionName()">Example 2.5</button></li>
<li><button type="button" class="btn btn-primary" onclick="yourFunctionName()">Example 2.6</button></li>
<li><button type="button" class="btn btn-primary" onclick="yourFunctionName()">Example 2.7</button></li>
<li><button type="button" class="btn btn-primary" onclick="yourFunctionName()">Example 2.8</button></li>
<li><button type="button" class="btn btn-primary" onclick="yourFunctionName()">Example 2.9</button></li>
<li><button type="button" class="btn btn-primary" onclick="yourFunctionName()">Example 2.10</button></li>
<li><button type="button" class="btn btn-primary" onclick="printOneToTen()">Example 2.1</button></li>
<li><button type="button" class="btn btn-primary" onclick="printOddNumbers()">Example 2.2</button></li>
<li><button type="button" class="btn btn-primary" onclick="printSquaresToOneHundred()">Example 2.3</button></li>
<li><button type="button" class="btn btn-primary" onclick="randomFour()">Example 2.4</button></li>
<li><button type="button" class="btn btn-primary" onclick="evenLessThanN(20)">Example 2.5</button></li>
<li><button type="button" class="btn btn-primary" onclick="powersOfTwo(8)">Example 2.6</button></li>
<li><button type="button" class="btn btn-primary" onclick="areWeThereYet()">Example 2.7</button></li>
<li><button type="button" class="btn btn-primary" onclick="triangle()">Example 2.8</button></li>
<li><button type="button" class="btn btn-primary" onclick="tableSquare()">Example 2.9</button></li>
<li><button type="button" class="btn btn-primary" onclick="extendedTableSquare(6)">Example 2.10</button></li>
</ul>
</section>

Expand Down
102 changes: 102 additions & 0 deletions js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,105 @@ var display = document.getElementById("display");
function yourFunctionName (){
display.innerHTML = "hello";
}

function printOneToTen() {
var result = "";
for (var i = 0; i < 10; i++) {
result += i + 1 + "<br/>";
}
display.innerHTML = result;
}

function printOddNumbers() {
var result = "";
for (var i = 1; i < 20; i += 2) {
result += i + "<br/>";
}
display.innerHTML = result;
}

function printSquaresToOneHundred() {
var result = "";
for (var i = 1; i < 10; i++) {
if (i * i < 100) {
result += i * i + "<br/>";
}
}
display.innerHTML = result;
}

function randomFour() {
var result = "";
for (var i = 0; i < 4; i++) {
var rando = Math.floor((Math.random() * 100) + 1);
result += rando + "<br/>";
}
display.innerHTML = result;
}

function evenLessThanN(n) {
var result = "";
for (var i = 2; i < n; i++) {
if (i % 2 == 0) {
result += i + "<br/>";
}
}
display.innerHTML = result;
}

function powersOfTwo(n) {
var result = "";
for (var i = 1; i <= n; i++) {
result += 2 ** i + "<br/>";
}
display.innerHTML = result;
}

function areWeThereYet() {
do {
var answer = prompt("Arewethereyet?")
} while (answer != "Yes");
display.innerHTML = "Good!";
}

function triangle() {
var symbol = "*";
var result = "";
for (var i = 0; i < 5; i++) {
result += symbol + "<br/>";
symbol += "*";
}
display.innerHTML = result;
}

function tableSquare() {
var result = "|";
for (var i = 1; i < 5; i++) {
for (var j = 1; j < 5; j++) {
result += i * j + "|";
}
if (i != 4) {
result += "<br/>|";
}
else {
result += "<br/>";
}
}
display.innerHTML = result;
}

function extendedTableSquare(n) {
var result = "|";
for (var i = 1; i < n + 1; i++) {
for (var j = 1; j < n + 1; j++) {
result += i * j + "|";
}
if (i != n) {
result += "<br/>|";
}
else {
result += "<br/>";
}
}
display.innerHTML = result;
}