diff --git a/index.html b/index.html index b16c318..6722c1a 100644 --- a/index.html +++ b/index.html @@ -20,16 +20,16 @@

Loops Exercises

diff --git a/js/script.js b/js/script.js index ba8cf69..6e4ca8b 100644 --- a/js/script.js +++ b/js/script.js @@ -2,6 +2,129 @@ var display = document.getElementById("display"); -function yourFunctionName (){ - display.innerHTML = "hello"; +function yourFunctionName(){ + display.innerHTML = "henlo Brian"; } + +function oneToTen(){ + display.innerHTML = "oneToTen()
***Output***"; + + for (var i = 1; i < 11; i++){ + display.innerHTML += "
" + i; + } +} + +function oddNumbers(){ + display.innerHTML = "oddNumbers()
***Output***"; + + for (var i = 1; i < 20; i+=2){ + display.innerHTML += "
" + i; + } +} + +function squares(){ + display.innerHTML = "squares()
***Output***"; + + for (var i = 1; i < 11; i++){ + display.innerHTML += "
" + i * i; + } +} + +function random4(){ + 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***"; + + for (var i = 2; i < 20; i+=2){ + display.innerHTML += "
" + i; + } +} + +function powers(){ + display.innerHTML = "powers()
***Output***"; + + for (var i = 1; i <= 8; i+=1){ + display.innerHTML += "
" + Math.pow(2,i); + } +} + +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; + } + +} + +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