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="oneToTen()">Example 2.1</button></li>
<li><button type="button" class="btn btn-primary" onclick="oddNumbers()">Example 2.2</button></li>
<li><button type="button" class="btn btn-primary" onclick="squareNumbers()">Example 2.3</button></li>
<li><button type="button" class="btn btn-primary" onclick="randomNumbers()">Example 2.4</button></li>
<li><button type="button" class="btn btn-primary" onclick="evenNumbers(20)">Example 2.5</button></li>
<li><button type="button" class="btn btn-primary" onclick="powers(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="tableSquareFour()">Example 2.9</button></li>
<li><button type="button" class="btn btn-primary" onclick="tableSquare(7)">Example 2.10</button></li>
</ul>
</section>

Expand Down
96 changes: 92 additions & 4 deletions js/script.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,95 @@
" use strict ";
'use strict'

var display = document.getElementById("display");
var display = document.getElementById('display')

function yourFunctionName (){
display.innerHTML = "hello";
function oneToTen () {
var output = ''
for (let i = 1; i <= 10; i++) {
output += i + '<br />'
}
display.innerHTML = output
}

function oddNumbers () {
var output = ''
for (let i = 1; i <= 20; i++) {
if (i % 2 !== 0) {
output += i + '<br />'
}
}
display.innerHTML = output
}
function squareNumbers () {
var output = ''
for (let i = 1; i <= 10; i++) {
output += Math.pow(i, 2) + '<br />'
}
display.innerHTML = output
}

function randomNumbers () {
var output = ''
for (let i = 0; i < 4; i++) {
output += Math.floor((Math.random() * 100) + 1) + '<br />'
}
display.innerHTML = output
}

function evenNumbers (n) {
var output = ''
for (let i = 1; i < n; i++) {
if (i % 2 === 0) {
output += i + '<br />'
}
}
display.innerHTML = output
}

function powers (n) {
var output = ''
for (let i = 1; i <= n; i++) {
output += Math.pow(2, i) + '<br />'
}
display.innerHTML = output
}

function areWeThereYet () {
var there = 'no'
while (there !== 'Yes') {
there = prompt('Are we there yet?')
}
display.innerHTML = 'Good!'
}

function triangle () {
var output = ''
for (let i = 1; i < 6; i++) {
for (let j = 0; j < i; j++) {
output += '*'
}
output += '<br />'
}
display.innerHTML = output
}

function tableSquareFour () {
var output = ''
for (let i = 1; i <= 4; i++) {
for (let j = 1; j <= 4; j++) {
output += '|' + i * j
}
output += '|<br />'
}
display.innerHTML = output
}

function tableSquare (n) {
var output = ''
for (let i = 1; i <= n; i++) {
for (let j = 1; j <= n; j++) {
output += '|' + i * j
}
output += '|<br />'
}
display.innerHTML = output
}