diff --git a/.idea/Java2JavaScript-Lab-1.iml b/.idea/Java2JavaScript-Lab-1.iml new file mode 100644 index 0000000..d6ebd48 --- /dev/null +++ b/.idea/Java2JavaScript-Lab-1.iml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..58714ad --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,57 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..20aab25 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..fc45183 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,702 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + DEFINITION_ORDER + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + project + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1484868947722 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/index.html b/index.html index b16c318..30a007e 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..a1621b6 100644 --- a/js/script.js +++ b/js/script.js @@ -1,7 +1,160 @@ " use strict "; var display = document.getElementById("display"); +var lineBreak = "
"; -function yourFunctionName (){ - display.innerHTML = "hello"; + +function oneToTen(){ + var output = "oneToTen() " + lineBreak; + output += "***Output***" + lineBreak; + + display.innerHTML = ""; + + + for(var i = 1; i <= 10; i++) { + output += i + lineBreak; + } + + display.innerHTML = output; +} + +function oddNumbers(){ + var output = "oddNumbers()" + lineBreak; + output += "***Output***" + lineBreak; + display.innerHTML = ""; + + for(var i = 1; i <= 20; i++){ + if((i % 2) != 0){ + output += i + lineBreak; + } + } + display.innerHTML = output; +} + +function squares(){ + var output = "squares()" + lineBreak; + var count = 1; + output += "***Output***" + lineBreak; + display.innerHTML = ""; + + for(var i = 1; i <= 10; i++){ + output += (count * count) + lineBreak; + count++; + } + display.innerHTML = output; +} + +function random4(){ + var output = "random4()" + lineBreak; + output += "***Output***" + lineBreak; + display.innerHTML = ""; + + for(var i = 1; i <= 4; i++){ + output += Math.floor((Math.random() * (100 - 1) + 1)) + lineBreak; + } + display.innerHTML = output; + + +} + +function even(x){ + var output = "even(20)" + lineBreak; + output += "***Output***" + lineBreak; + display.innerHTML = ""; + + for(var i = 1; i < x; i++){ + if((i % 2) == 0){ + output += i + lineBreak; + } + } + display.innerHTML = output; } + +function powers(y){ + var output = "powers(8)" + lineBreak; + output += "***Output***" + lineBreak; + display.innerHTML = ""; + + for(var i = 1; i <= y; i++){ + output += Math.pow(2, i) + lineBreak; + } + display.innerHTML = output; + +} + +function areWeThere(){ + var answer; + display.innerHTML=""; + do { + display.innerHTML += "Arewethereyet" + lineBreak; + + answer = prompt("Arewethereyet?", ""); + if (answer != null) { + if (answer == "yes") { + display.innerHTML += "Good"; + } else { + display.innerHTML += answer + lineBreak; + } + } + } + while (answer != "yes"); + +} + +function triangle(){ + var star = "*"; + display.innerHTML=""; + var output = "***Output***"; + + for(var i = 0; i < 6; i++){ + for(var j = 0; j < i; j++){ + output += star; + } + output += lineBreak; + } + display.innerHTML = output; +} + +function tableSquare(){ + display.innerHTML=""; + var blankSpace = ' '; + var output = "tableSquares()" + lineBreak; + output = "***Output***" + lineBreak; + + for(var i = 1; i < 5; i++){ + output += "|"; + for(var j = 1; j < 5; j++){ + var answer = i*j; + if(answer<10){ + output += blankSpace + blankSpace + i * j + "|"; + } else { + output += i * j + "|"; + } + } + output += lineBreak; + } + display.innerHTML = output; +} + +function tableSquares(x) { + display.innerHTML=""; + var blankSpace = ' '; + var output = "tableSquares(6)" + lineBreak; + output = "***Output***" + lineBreak; + + for(var i = 1; i < (x+1); i++){ + output += "|"; + for(var j = 1; j < (x+1); j++){ + var answer = i*j; + if(answer<10){ + output += blankSpace + blankSpace + i * j + "|"; + } else { + output += i * j + "|"; + } + } + output += lineBreak; + } + display.innerHTML = output; +} + +