diff --git a/Week1/homework/calculator/bkgd.png b/Week1/homework/calculator/bkgd.png new file mode 100644 index 000000000..d457eb3e6 Binary files /dev/null and b/Week1/homework/calculator/bkgd.png differ diff --git a/Week1/homework/calculator/calc.svg b/Week1/homework/calculator/calc.svg new file mode 100644 index 000000000..bb63137db --- /dev/null +++ b/Week1/homework/calculator/calc.svg @@ -0,0 +1,324 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Week1/homework/calculator/index.html b/Week1/homework/calculator/index.html new file mode 100644 index 000000000..fad118b57 --- /dev/null +++ b/Week1/homework/calculator/index.html @@ -0,0 +1,53 @@ + + + + + + + Simple Calculator + + + + + + +
+

Simple Calculator

+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + \ No newline at end of file diff --git a/Week1/homework/calculator/main.css b/Week1/homework/calculator/main.css new file mode 100644 index 000000000..ac6447b1c --- /dev/null +++ b/Week1/homework/calculator/main.css @@ -0,0 +1,88 @@ +body{ + background-color: burlywood; +} +.container { + background-image: url(bkgd.png); + background-position: inherit; + background-repeat: no-repeat; + text-align: center; + width: 309px; + height: 500px; + padding:inherit; +} + +h4 { + color: lightblue; + text-align: left; + padding-left: 35px; + padding-top: 15px; +} + +button { + width: 60px; + height: 50px; + font-size: 22px; + background-color: gray; + color: #fee; + border: 4px gray outset; + border-radius: 9px; + cursor: pointer; +} + +.top { + height: 30px; + background-color: li; + box-shadow: 3px 2px 3px black; + border-radius: 4px; + border: 1px outset; + color: #bec; + text-shadow: 2px 2px 20px white; + font-size: 20px; +} + +#c { + width: 80%; + height: 50px; + color: black; +} + +button:active { + background-color: gray; + outline: 1px solid grey; + border: 3px gainsboro inset; +} + +.top:hover{ + box-shadow: inset 5px 5px 5px grey, inset -5px -5px 5px white; +} + +button:hover{ + background-color: gainsboro; +} + +.top:active{ + background-color: gainsboro; + outline: 1px solid gray; + border: 3px gainsboro inset; +} +#display-container { + border: 19px inset; + margin-bottom: 29px; +} + +#h1, #display1 { + width: inherit; + height: 25px; + background-color:powderblue; + font-size: 20px; + font-family: serif; + font-weight: bold; + text-align: right; + overflow: hidden; + color: black; + text-shadow: 2px 2px 1px #9aa; +} +#display1 { + font-size: 16px; + padding-bottom: 10px; +} \ No newline at end of file diff --git a/Week1/homework/calculator/main.js b/Week1/homework/calculator/main.js new file mode 100644 index 000000000..bc39ef2b3 --- /dev/null +++ b/Week1/homework/calculator/main.js @@ -0,0 +1,208 @@ +let decimalPoint, enter, entered, operatorSign, rootNpower_Sign, flo, firstI, first, second, secondI, answer, theanswer, result; +let opsCheck, dotCounter; +let removeFirstZero; + +function dot(b) { + if (decimalPoint == "") { + enter = entered = b; + first+= enter; + entered+= enter; + decimalPoint = "."; + dotCounter = 0; + return first; + } else { + return first; + } +} + +function c(c) { + document.getElementById("display1").innerHTML = decimalPoint = operatorSign = rootNpower_Sign = entered = math = first = firstI = second = secondI = answer = theanswer = flo = M = ""; + return ""; +} + +c(); + +function maths(a) { + math = a; + try { + if (operatorSign == "+") { + firstI = first - second; + mathematics(); + first = second + "+" + result; + } else if (operatorSign == "-") { + firstI = second - first; + mathematics(); + first = second + "-" + "(" + result + ")"; + } else if (operatorSign == "*") { + firstI = first / second; + mathematics(); + first = second + "*" + result; + } else if (operatorSign == "/") { + firstI = second / first; + mathematics(); + first = second + "/" + result; + } else { + firstI = first; + mathematics(); + first = result; + } + return first; + } catch (first ) { + first = second + operatorSign; + return first; + } +} + +function digit(b) { + opsCheck = 0; + dotCounter++; + if (first == Infinity || first == NaN) { + first = 0; + } + peSign = "pes"; + entered = b; + if (rootNpower_Sign != "") { + first = (first === "0" && entered !== ".") ? entered: first + entered; + return secondI + firstI + rootNpower_Sign + first; + } else { + first = (first === "0" && entered !== ".") ? entered: first + entered; + theanswer = eval(first) + ""; + if (theanswer.length > 14) { + theanswer = Math.abs((theanswer*1).toPrecision(14)); + } + document.getElementById("display1").innerHTML = first; + return theanswer; + } +} + +function operators(b) { + peSign = ""; + if (opsCheck == 0) { + opsCheck = 1; + document.getElementById("display1").innerHTML = first; + try { + if (rootNpower_Sign == "^") { + if (operatorSign == "+") { + answer = result + second; + } else if (operatorSign == "-") { + answer = second - result; + } else if (operatorSign == "*") { + answer = result * second; + } else if (operatorSign == "/") { + answer = second / result; + } else { + answer = result; + } + } else if (rootNpower_Sign == "√") { + if (operatorSign == "+") { + answer = second + result; + } else if (operatorSign == "-") { + answer = second - result; + } else if (operatorSign == "*") { + answer = result * second; + } else if (operatorSign == "/") { + answer = second / result; + } else { + answer = result; + } + } else if (a == "%") { + answer = second % first; + } else { + operatorSign = b; + first += operatorSign; + decimalPoint = ""; + } + rootNpower_Sign = ""; + operatorSign = b; + firstI = ""; + second = answer; + first = answer + operatorSign; + decimalPoint = ""; + +document.getElementById("display1").innerHTML = first; + return eval(second); + } catch(x) { + if (first != "Press ON to start") { + operatorSign = b; + second = eval(first); + first += operatorSign; + decimalPoint = ""; + } else { + first = "Press ON to start" ; + } + document.getElementById("display1").innerHTML = first; + return (second == undefined ) ? 0 : eval(second); + } + } else { + operatorSign = b; + first += ""; + first = first.substr(0, first.length - 1); + first = first + operatorSign; + document.getElementById("display1").innerHTML = first; + return (second == undefined ) ? 0 : eval(second); + } +} + +function equal() { + document.getElementById("display1").innerHTML = first; + try { + if (rootNpower_Sign == "^") { + if (operatorSign == "+") { + first = result + second; + } else if (operatorSign == "-") { + first = second - result; + } else if (operatorSign == "*") { + answer = result * second; + first = answer; + } else if (operatorSign == "/") { + first = second / result; + } else { + first = result; + } + } else if (rootNpower_Sign == "√") { + if (operatorSign == "+") { + first = result + second; + } else if (operatorSign == "-") { + first = second - result; + } else if (operatorSign == "*") { + first = result * second; + } else if (operatorSign == "/") { + first = second / result; + } else { + first = result; + } + } else if (operatorSign == "%") { + answer = second % first; + } else { + if (first == "") { + first = first ; + } else { + try{ + first = eval(first) + ""; + if (first.length > 14) { + first = Math.abs((first*1).toPrecision(14)); + } + } catch (first) { + first = "Incorrect input. Click C to clear"; + return first; + first = ""; + } + } + } + rootNpower_Sign = operatorSign = answer = firstI = second = ""; + flo = first; + flo = Math.floor(flo); + decimalPoint = (flo == first) ? "": "."; + return first; + } catch(operatorSign) { + operatorSign = ""; + first = eval(first) + ""; + if (first.length > 14) { + first = Math.abs((first*1).toPrecision(14)); + } + flo = first; + flo = Math.floor(flo); + decimalPoint = (flo == first) ? "": "."; + return first; + } +} \ No newline at end of file diff --git a/Week1/homework/index.html b/Week1/homework/index.html deleted file mode 100644 index e69de29bb..000000000 diff --git a/Week1/homework/js-exercises/JS1_w1e10_arrCompare.js b/Week1/homework/js-exercises/JS1_w1e10_arrCompare.js new file mode 100644 index 000000000..33732efb2 --- /dev/null +++ b/Week1/homework/js-exercises/JS1_w1e10_arrCompare.js @@ -0,0 +1,15 @@ +'use strict' + +const arr1 = [123,234,0,1]; //1 +const arr2 = [192,168,1,1,255,0,0]; //1 + +console.log("The length of the arr1 is " + arr1.length + " and the length of the arr2 is " + arr2.length); //2 + +if(arr1.length === arr2.length) console.log("arr1 and arr2 has the same length"); //3 +else console.log("arr1 and arr2 has not the same length"); //3 + +/* +1. Declare 2 variables, that each hold an array. The first array should have 4 items, the second 7 items +2. Find out how to get the length of each array. Write a `console.log` statement that shows the length of each array +3. Write a conditional statement that checks if both are of equal length. If they are, log to the console `They are the same!`, if not log `Two different sizes` +*/ \ No newline at end of file diff --git a/Week1/homework/js-exercises/JS1_w1e1_helloWorld.js b/Week1/homework/js-exercises/JS1_w1e1_helloWorld.js new file mode 100644 index 000000000..44cf5c04e --- /dev/null +++ b/Week1/homework/js-exercises/JS1_w1e1_helloWorld.js @@ -0,0 +1,12 @@ +'use strict' + +console.log("Hello World"); // English +console.log("Γειά σου Κόσμε"); // Greek +console.log("Labas Pasauli"); // Lithuanian +console.log("Hallo Welt"); // German +console.log("Selam Dünya"); // Turkish +console.log("Ciao Mondo"); // Italian +console.log("Witaj świecie"); // Polish +console.log("Hei Verden"); // Norwegian +console.log("Hej Världen"); // Swidish +console.log("Ahoj Světe"); // Czech \ No newline at end of file diff --git a/Week1/homework/js-exercises/JS1_w1e2_errorDebug.js b/Week1/homework/js-exercises/JS1_w1e2_errorDebug.js new file mode 100644 index 000000000..a31e1f450 --- /dev/null +++ b/Week1/homework/js-exercises/JS1_w1e2_errorDebug.js @@ -0,0 +1,3 @@ +'use strict' + +console.log("I'm awesome"); \ No newline at end of file diff --git a/Week1/homework/js-exercises/JS1_w1e3_logTheNum.js b/Week1/homework/js-exercises/JS1_w1e3_logTheNum.js new file mode 100644 index 000000000..0ab5d84cc --- /dev/null +++ b/Week1/homework/js-exercises/JS1_w1e3_logTheNum.js @@ -0,0 +1,19 @@ +'use strict' + + +let numberX; //1 +console.log("numberX is undefined."); //2 +console.log(numberX); //3 +numberX = 1; //4 +console.log("now numberX is integer."); //5 +console.log(numberX); //6 + + +/*Follow the steps. Make sure that each step is written on the line after. + +1. First, declare your variable `numberX`. Do not _initialize_ it (which means, don't give it a value) yet. +2. Add a `console.log` statement that explains in words _what you think_ the value of `x` is, like in this example. +3. Add a `console.log` statement that logs the value of `numberX`. +4. Now _initialize_ your variable `numberX` with a number (also called an `integer` in computer science terms). +5. Next, add a `console.log` statement that explains _what you think_ the value of `numberX` is. +6. Add a `console.log` statement that logs the value of `numberX`.*/ \ No newline at end of file diff --git a/Week1/homework/js-exercises/JS1_w1e4_logTheString.js b/Week1/homework/js-exercises/JS1_w1e4_logTheString.js new file mode 100644 index 000000000..7f36d2cdb --- /dev/null +++ b/Week1/homework/js-exercises/JS1_w1e4_logTheString.js @@ -0,0 +1,16 @@ +'use strict' + +let myString = "George Mouzakis"; //1 +console.log("myString variable is a string.") //2 +console.log(myString); //3 +myString = "Hello World"; //4 +console.log("myString variable still to be a string.") //5 +console.log(myString); //6 + +/* +1. Declare a variable `myString` and assign a string to it. Use your full name, including spaces, as the content for the string. +2. Write a `console.log` statement in which you explain in words _what you think_ the value of the string is. +3. Now `console.log` the variable `myString`. +4. Now reassign to the variable `myString` a new string. +5. Just like what you did before write a `console.log` statement that explains in words _what you think_ will be logged to the console. +6. Now console.log `myString` again.*/ \ No newline at end of file diff --git a/Week1/homework/js-exercises/JS1_w1e5_roundAndLog.js b/Week1/homework/js-exercises/JS1_w1e5_roundAndLog.js new file mode 100644 index 000000000..de6bdc15c --- /dev/null +++ b/Week1/homework/js-exercises/JS1_w1e5_roundAndLog.js @@ -0,0 +1,18 @@ +'use strict' + +let z = 7.25; //1 +console.log(z); //2 +let a = Math.round(z); //3 +console.log(a); //4 +let x = 0; +if (z