Skip to content
Closed
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
2 changes: 1 addition & 1 deletion css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,4 @@ h1 {font-weight: bold; margin-left: 10px;}

#menu button {
width: 120px;
}
}
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(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="tableSquare()">Example 2.9</button></li>
<li><button type="button" class="btn btn-primary" onclick="tableSquares(6)">Example 2.10</button></li>
</ul>
</section>

Expand Down
102 changes: 101 additions & 1 deletion js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,106 @@

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

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

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

function oneToTen(){
display.innerHTML = "oneToTen()<br>***Output***<br>";
for (var i = 1;i <= 10; i++){
display.innerHTML += i + "<br>";
}
}

function oddNumbers(){
display.innerHTML = "oddNumbers()<br>***Output***<br>";
for (var i = 0; i < 20; i++){
if (i % 2 != 0){
display.innerHTML += i + "<br>";
}
}
}

function squares(){
display.innerHTML = "squares()<br>***Output***<br>";
var maxCount = 100;
for (var i = 1; (i*i) <= maxCount; i++){
display.innerHTML += (i*i) + "<br>";
}
}

function random4(){
display.innerHTML = "random4()<br>***Output***<br>";
var maxRandomNumbers = 4;
for (var i = 0; i < maxRandomNumbers; i++){
display.innerHTML += Math.floor(Math.random() * 10) + "<br>";
}
}

function even(evenNumbers){
display.innerHTML = "even(" + evenNumbers + ")<br>***Output***<br>";
for (var i = 2; i < evenNumbers; i += 2){
display.innerHTML += i + "<br>";
}
}

function powers(powersNumbers){
display.innerHTML = "powers(" + powersNumbers + ")<br>***Output***<br>";
for (var i = 1; i <= powersNumbers ; i++){
display.innerHTML += (i*i) + "<br>";
}
}

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

function triangle(){
display.innerHTML = "triangle()<br>***Output***<br>";
var size = 5;
for (var i = 1; i <= size; i++){
for (var j = 0; j < i; j++){
display.innerHTML += "*";
}
display.innerHTML += "<br>";
}
}

function tableSquare(){
display.innerHTML = "tableSquare()<br>***Output***<br>A4x4tablesquare<br>";
for (var i = 1; i <=4; i++){
display.innerHTML += "|";
for (var j = 1; j <=4; j++){
if ((i*j) < 10){
display.innerHTML += "&nbsp&nbsp" + i*j + "|";
} else {
display.innerHTML += i*j + "|";
}
}
display.innerHTML += "<br>";
}
}

function tableSquares(n){
display.innerHTML = "tableSquare(" + n + ")<br>***Output***<br>A" + n + "x" + n + "tablesquare<br>";
for (var i = 1; i <= n; i++){
display.innerHTML += "|";
for (var j = 1; j <= n; j++){
if ((i*j) < 10){
display.innerHTML += "&nbsp&nbsp" + i*j + "|";
} else {
display.innerHTML += i*j + "|";
}
}
display.innerHTML += "<br>";
}
}