From 6685b50482a79cdb2780cd18b1833e9b791ffeb9 Mon Sep 17 00:00:00 2001 From: Brian Mullin Date: Thu, 25 May 2017 14:14:09 -0400 Subject: [PATCH 1/2] Almost done --- index.html | 14 +++++----- js/script.js | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 83 insertions(+), 8 deletions(-) diff --git a/index.html b/index.html index b16c318..9c91784 100644 --- a/index.html +++ b/index.html @@ -20,13 +20,13 @@

Loops Exercises

diff --git a/js/script.js b/js/script.js index 5c82170..6e4ca8b 100644 --- a/js/script.js +++ b/js/script.js @@ -2,21 +2,20 @@ var display = document.getElementById("display"); -function yourFunctionName (){ +function yourFunctionName(){ display.innerHTML = "henlo Brian"; } -function oneToTen (){ - - display.innerHTML = "oneToTen()
\*\*\*Output\*\*\*"; +function oneToTen(){ + display.innerHTML = "oneToTen()
***Output***"; + for (var i = 1; i < 11; i++){ display.innerHTML += "
" + i; - }; + } } function oddNumbers(){ - - display.innerHTML = "oddNumbers()
\*\*\*Output\*\*\*"; + display.innerHTML = "oddNumbers()
***Output***"; for (var i = 1; i < 20; i+=2){ display.innerHTML += "
" + i; @@ -24,8 +23,7 @@ function oddNumbers(){ } function squares(){ - - display.innerHTML = "squares()
\*\*\*Output\*\*\*"; + display.innerHTML = "squares()
***Output***"; for (var i = 1; i < 11; i++){ display.innerHTML += "
" + i * i; @@ -33,17 +31,15 @@ function squares(){ } function random4(){ - - display.innerHTML = "random4()
\*\*\*Output\*\*\*"; + display.innerHTML = "random4()
***Output***"; for (var i = 1; i <= 4; i++){ display.innerHTML += "
" + Math.floor((Math.random() * 10) + 1); } } -function even(){ - - display.innerHTML = "even()
\*\*\*Output\*\*\*"; +function even(){ + display.innerHTML = "even()
***Output***"; for (var i = 2; i < 20; i+=2){ display.innerHTML += "
" + i; @@ -51,8 +47,7 @@ function even(){ } function powers(){ - - display.innerHTML = "powers()
\*\*\*Output\*\*\*"; + display.innerHTML = "powers()
***Output***"; for (var i = 1; i <= 8; i+=1){ display.innerHTML += "
" + Math.pow(2,i); @@ -60,23 +55,76 @@ function powers(){ } 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()
***Output***"; + + for (var i = 1; i < 6; i+=1){ + triangle += "*"; + display.innerHTML += "
" + triangle; + } - display.innerHTML = "triangle()
\*\*\*Output\*\*\*"; +} + +function tableSquare(){ + display.innerHTML = "tableSquare()
***Output***"; + var table = ""; + for (var i=1; i <= 4; i++){ + table += "
"; + + 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()
***Output***"; + var table = ""; + + for (var i=1; i <= n; i++){ + table += "
"; + + 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; + +} \ No newline at end of file