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
22 changes: 11 additions & 11 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@
</header>

<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()">OneToTen</button></li>
<li><button type="button" class="btn btn-primary" onclick="oddNumb()">OddNumb</button></li>
<li><button type="button" class="btn btn-primary" onclick="squares()">Squares</button></li>
<li><button type="button" class="btn btn-primary" onclick="random4Num()">Random4Num</button></li>
<li><button type="button" class="btn btn-primary" onclick="evenNum()">EvenNum</button></li>
<li><button type="button" class="btn btn-primary" onclick="powersOf2()">PowerOf2</button></li>
<li><button type="button" class="btn btn-primary" onclick="areWeThereYet()">AreWeThereYet</button></li>
<li><button type="button" class="btn btn-primary" onclick="triangle()">Triangle</button></li>
<li><button type="button" class="btn btn-primary" onclick="tableSquare()">TableSquare(</button></li>
<li><button type="button" class="btn btn-primary" onclick="tableSquares()">TableSquares</button></li>

</ul>
</section>

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

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

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

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

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

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

function evenNum(){
var n = prompt("Enter your number");
var result = "even(" + n + ")<br>*** Output ***";
for (var i = 1; i < n; i++) {
if (i % 2 == 0) {
result += "<br>" + i;
}
}
display.innerHTML = result;
}

function powersOf2(){
var n = prompt("Enter your number");
var result = "powersof2(" + n + ")<br>*** Output ***";
for (var i = 1; i <= n; i++){
result += "<br>" + Math.pow(2, i);
}
display.innerHTML = result;
}

function areWeThereYet(){
do {var n = prompt("Are we there yet?");}
while (n.toLowerCase() !== "yes");
display.innerHTML = "Good!";
}

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

function tableSquare(){
var result = "tableSquare()<br>*** Output ***<br>A4*4tablesquare<br>";
outerloop: // for rows
var multiplier = 4;
for(var i = 1; i <= 16; i++){
if (i%4 == 0){
result += "| " + i + " |<br>";
} else {
result += "| " + i + " ";
}
}
display.innerHTML = result;
}

function tableSquares(){
var n = prompt("Enter your number");
var result = "tableSquare<br>*** Output ***<br>A"+n+"*"+n+"tablesquare<br >";
outerloop: // for rows
for(var i = 1; i <= n*n; i++){
if (i%n == 0){
result += "| " + i + " |<br>";
} else {
result += "| " + i + " ";
}
}
display.innerHTML = result;
}