From 189ec170051a5849f8b8060c13bf21d20b018704 Mon Sep 17 00:00:00 2001 From: Andres Holland Date: Fri, 20 Jan 2017 17:31:36 -0500 Subject: [PATCH] initial submit --- css/style.css | 6 ++++ index.html | 23 +++++++------ js/script.js | 93 +++++++++++++++++++++++++++++++++++++++++++++++++-- js/test | 0 4 files changed, 109 insertions(+), 13 deletions(-) create mode 100644 js/test diff --git a/css/style.css b/css/style.css index 976122b..d006507 100644 --- a/css/style.css +++ b/css/style.css @@ -139,3 +139,9 @@ h1 {font-weight: bold; margin-left: 10px;} #menu button { width: 120px; } + +#menu buttonReset { + width: 120px; + color: FFFFFF; + background: red; +} diff --git a/index.html b/index.html index b16c318..bffc2cd 100644 --- a/index.html +++ b/index.html @@ -16,20 +16,21 @@ -

Loops Exercises

+

Loops Exercises - Andres

diff --git a/js/script.js b/js/script.js index ba8cf69..bb64938 100644 --- a/js/script.js +++ b/js/script.js @@ -2,6 +2,95 @@ var display = document.getElementById("display"); -function yourFunctionName (){ - display.innerHTML = "hello"; +function oneToTen () { + for (var i = 1; i < 11; i++) { + display.innerHTML += i + '
'; + } +} + +function oddNumbers () { + for (var i = 1; i < 20; i++) { + if (i % 2 !== 0) { + display.innerHTML += i + '
'; + } + } +} + +function squares () { + var squaredNumber = 1, counter = 1; + while (squaredNumber < 101) { + display.innerHTML += squaredNumber + '
'; + counter ++; + squaredNumber = counter * counter; + } +} + +function random4 () { + var random, randomInt; + for (var i = 1; i < 5; i++) { + random = Math.random() * 100; + randomInt = Math.round(random); + display.innerHTML += randomInt + '
'; + } +} + +function even (n) { + for (var i = 1; i < n; i++) { + if (i % 2 === 0) { + display.innerHTML += i + '
'; + } + } +} + +function powers (n) { + for (var i = 1; i <= n; i++) { + display.innerHTML += Math.pow(2,i) + '
'; + } +} + +function annoying () { + var answer; + do { + answer = prompt("Arewethereyet?"); + display.innerHTML += answer + '
'; + } + while (answer !== "Yes") + display.innerHTML += "Good"; +} + +//String.prototype.Repeat could solve this without the use of a nested loop +function triangle () { + var line = ""; + for (var i = 1; i < 6; i++) { + for (var j = i; j < 6; j++) { + line += "*"; + break; + } + display.innerHTML += line + '
'; + } +} + +function tableSquare () { + for (var i = 1; i < 5; i++) { + for (var j = i; j < 5; j++) { + display.innerHTML += (j + "|") + (j * 2 + "|") + (j * 3 + "|") + (j * 4 + "|") + '
'; + break; + } + } +} + +function tableSquares (n) { + var currentResult; + for (var i = 1; i <= n; i++) { + var string = ""; + for (var j = 1; j <= n; j++) { + currentResult = i * j; + string += currentResult + " | "; + } + display.innerHTML += string + '
'; + } +} + +function reset () { + display.innerHTML = ""; } diff --git a/js/test b/js/test new file mode 100644 index 0000000..e69de29