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="printNumbersOneToTen()">Example 2.1</button></li>
<li><button type="button" class="btn btn-primary" onclick="odd()">Example 2.2</button></li>
<li><button type="button" class="btn btn-primary" onclick="squareNumbersto100()">Example 2.3</button></li>
<li><button type="button" class="btn btn-primary" onclick="randomNumberGenerator()">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="powersOfTwo(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
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 printNumbersOneToTen(){
display.innerHTML=("oneToTen<br>***Output***");
for(var i=1;i<=10;i++){
display.innerHTML+=("<br>" +i);
}
}
function odd(){
display.innerHTML=("oddNumbers()<br>***Output***");
for(var i=1;i<20;i+=2){
display.innerHTML+=("<br>"+i);
}
}
function squareNumbersto100(){
display.innerHTML=("squares()<br>***Output***");
for(var i=1;i<=10;i++){
display.innerHTML+=("<br>"+ i*i);
}
}

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

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

function powersOfTwo(n){
display.innerHTML=("***Output***");
for(var i=1;i<=n;i++){
display.innerHTML+="<br>" + Math.pow(2, i);
}
}

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

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

}
display.innerHTML="Good!";
}

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

function tableSquare(){
display.innerHTML="tableSquare()<br>***Output***<br>";
var filledTable="";
for(var i=1;i<=4;i++){
filledTable+="<br>"

for (var j=1;j<4;j++){
filledTable+="|";
var multiple= i*j;
if (multiple<=9){
filledTable+= "\xa0"+multiple+ " \xa0 ";
}
else if(multiple>=10){
filledTable+= " " +multiple + " ";
}
}
filledTable+="|";

}
display.innerHTML+=filledTable;
}

function tableSquares(n){
display.innerHTML="tableSquare()<br>***Output***<br>";
var filledTable="";
for(var i=1;i<=n;i++){
filledTable+="<br>"

for (var j=1;j<=n;j++){
filledTable+="|";
var multiple= i*j;
if (multiple<=9){
filledTable+= "\xa0 "+multiple+ "\xa0 "
}
else if(multiple>=10){
filledTable+= " " +multiple + " ";
}
}
filledTable+="|";

}
display.innerHTML+=filledTable;
}