From b797e9a1ef79b10d92a778545c4d2911611ccfae Mon Sep 17 00:00:00 2001 From: Chris Date: Wed, 24 May 2017 17:21:17 -0400 Subject: [PATCH] Finished loop lab --- index.html | 20 +++++++-------- js/script.js | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 80 insertions(+), 12 deletions(-) diff --git a/index.html b/index.html index b16c318..40bde50 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..0cd6fff 100644 --- a/js/script.js +++ b/js/script.js @@ -2,6 +2,74 @@ var display = document.getElementById("display"); -function yourFunctionName (){ - display.innerHTML = "hello"; +function oneToTen(){ + for (i = 1; i <= 10; i++) { + display.innerHTML += i + "
"; + } +} + +function oddNumbers(){ + for (i = 1; i <= 20; i+=2) { + display.innerHTML += i + "
"; + } +} + +function squareNumbers(){ + for (i = 1; i <= 10; i++) { + display.innerHTML += i * i + "
"; + } +} + +function random4(){ + var result; + for(i = 1; i <= 4; i++){ + result = Math.round(Math.random() * 99) + 1; + display.innerHTML += result + "
" + } +} + +function even(n){ + for (i = 2; i < n; i+=2) { + display.innerHTML += i + "
"; + } +} + +function powers(n){ + for (i = 1; i <= n; i++) { + display.innerHTML += Math.pow(2,i) + "
"; + } +} + +function thereYet(){ + var quit = "no"; + while(quit != "yes"){ + quit = prompt("Are we there yet?"); + } +} + +function triangle(n){ + for (i = 1; i <= n; i++) { + for(j = 1; j <= i; j++){ + display.innerHTML += "*"; + } + display.innerHTML += "
"; + } +} + +function tableSquare(){ + for (i = 1; i <= 4; i++) { + for(j = 1; j <= 4; j++){ + display.innerHTML += i * j + "| "; + } + display.innerHTML += "
"; + } +} + +function tableSquare(n){ + for (i = 1; i <= n; i++) { + for(j = 1; j <= n; j++){ + display.innerHTML += i * j + "| "; + } + display.innerHTML += "
"; + } }