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="squares()">Example 2.3</button></li>
<li><button type="button" class="btn btn-primary" onclick="random4()">Example 2.4</button></li>
<li><button type="button" class="btn btn-primary" onclick="even()">Example 2.5</button></li>
<li><button type="button" class="btn btn-primary" onclick="powers()">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="tableSquares(10)">Example 2.10</button></li>
</ul>
</section>

Expand Down
127 changes: 125 additions & 2 deletions js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,129 @@

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

function yourFunctionName (){
display.innerHTML = "hello";
function yourFunctionName(){
display.innerHTML = "henlo Brian";
}

function oneToTen(){
display.innerHTML = "oneToTen()<br>***Output***";

for (var i = 1; i < 11; i++){
display.innerHTML += "<br>" + i;
}
}

function oddNumbers(){
display.innerHTML = "oddNumbers()<br>***Output***";

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

function squares(){
display.innerHTML = "squares()<br>***Output***";

for (var i = 1; i < 11; i++){
display.innerHTML += "<br>" + i * i;
}
}

function random4(){
display.innerHTML = "random4()<br>***Output***";

for (var i = 1; i <= 4; i++){
display.innerHTML += "<br>" + Math.floor((Math.random() * 10) + 1);
}
}

function even(){
display.innerHTML = "even()<br>***Output***";

for (var i = 2; i < 20; i+=2){
display.innerHTML += "<br>" + i;
}
}

function powers(){
display.innerHTML = "powers()<br>***Output***";

for (var i = 1; i <= 8; i+=1){
display.innerHTML += "<br>" + Math.pow(2,i);
}
}

function areWeThereYet(){
var answer = prompt("Are we there?");

while(answer != "yes"){
answer = prompt("Are we there yet?");

}
display.innerHTML = "Good!";
}

function triangle(){
var triangle = "";
display.innerHTML = "triangle()<br>***Output***";

for (var i = 1; i < 6; i+=1){
triangle += "*";
display.innerHTML += "<br>" + triangle;
}

}

function tableSquare(){
display.innerHTML = "tableSquare()<br>***Output***";
var table = "";

for (var i=1; i <= 4; i++){
table += "<br>";

for (var j=1; j <= 4; j++){
table += "|";
var multiple = i*j;

if (multiple <= 9){
table += "\xa0" + multiple + " \xa0 ";
}
else if(multiple < 100){
table += " " + multiple + " ";
}
}
table += "|";
}

display.innerHTML += table;

}

function tableSquares(n){
display.innerHTML = "tableSquares()<br>***Output***";
var table = "";

for (var i=1; i <= n; i++){
table += "<br>";

for (var j=1; j <= n; j++){
table += "|";
var multiple = i*j;

if (multiple <= 9){
table += "\xa0" + multiple + " \xa0 ";

}else if(multiple <= 99){
table += " " + multiple + " ";

}else{
table += "" + multiple + "";
}
}
table += "|";
}

display.innerHTML += table;

}