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="tableSquareN()">Example 2.10</button></li>
</ul>
</section>

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


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

function oddNumbers(){
var addNum="oddNumbers()</br>***Output***</br>";
for(var i=1; i<=20;i=i+2){
addNum+=i +"</br>";
}
display.innerHTML =addNum;
}

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

function random4(){
var addRandom="random4()</br>***Output***</br>";
for(var i=1; i<=4;i++){
addRandom+= parseInt((Math.random()*100)+1)+"</br>";
}
display.innerHTML=addRandom;
}


function even(){
var n = prompt("Even number up to n, Enter n: ");
if(n != null){
var addEven="even("+n+ ")</br>***Output***</br>";
for(var i=2; i<n; i=i+2){
addEven+= i+"</br>";
}
display.innerHTML=addEven;
}
}

function powers(){
var n = prompt("Powers up to 2^n, Enter n: ");
if(n != null){
var addPower="powers("+n+ ")</br>***Output***</br>";
for(var i=1; i<=n; i++){
addPower+= Math.pow(2,i)+"</br>";
}
display.innerHTML=addPower;
}
}

function areWeThereYet(){
var ans="no";
var totalAns="";
while(ans.toLowerCase() !="yes"){
ans= prompt("Arewethereyet?");
totalAns+="Arewethereyet?</br>" +ans+ "</br>";
if(ans.toLowerCase() =="yes"){
totalAns+="Good!";
display.innerHTML=totalAns;
}
}
}

function triangle(){
var outPut="***Output***</br>";
var tri="";
for(var i=1; i<=5;i++){
tri += "*";
outPut += tri +"</br>";
}
display.innerHTML=outPut;
}

function tableSquare(){
var outPut="tableSquare()</br>***Output***</br>A4x4tablesquare</br>";
for(var i=1; i<=4;i++){
for(var j=1; j<=4; j++){

outPut+= (" | ") +(i*j);
}
outPut+=" | </br>";
}
display.innerHTML=outPut;
}

function tableSquareN(){
var n = prompt("n x n table, Enter n: ");
var outPut="tableSquare("+n+")</br>***Output***</br>A"+n+"x"+n+"tablesquare</br>";
for(var i=1; i<=n;i++){
for(var j=1; j<=n; j++){

outPut+= (" | ") +(i*j);
}
outPut+=" | </br>";
}
display.innerHTML=outPut;
}