Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions Week1/homework/js calculator/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
body{
width: 1920px;
height: 1024px;
}

.main, table{
width: 400px;
height: 400px;
background-color: gainsboro;
}



.textview{
background-color: greenyellow;
width: 100%;
border:4px;
font-size: 40px;
border-style:inset;
text-align: center;
}

.button{
background-color: silver;
width: 100%;
height: 100%;
font-size: 30px;
border-radius: 15px;
}
44 changes: 44 additions & 0 deletions Week1/homework/js calculator/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<html>
<head>
<link rel="stylesheet" type="text/css" href="index.css">
</head>
<body>
<div class="main">
<form name="form">
<input class="textview" name="textview">
</form>
<table>
<tr>
<td><input class ="button" type="button" value="C" onclick="clean()"></td>
<td><input class ="button" type="button" value="<" onclick="back()"></td>
<td><input class ="button" type="button" value=" / " onclick="insert('/')"></td>
<td><input class ="button" type="button" value=" * " onclick="insert('*')"></td>
</tr>
<tr>
<td><input class ="button" type="button" value="7" onclick="insert(7)"></td>
<td><input class ="button" type="button" value="8" onclick="insert(8)"></td>
<td><input class ="button" type="button" value="9" onclick="insert(9)"></td>
<td><input class ="button" type="button" value=" - " onclick="insert('-')"></td>
</tr>
<tr>
<td><input class ="button" type="button" value="4" onclick="insert(4)"></td>
<td><input class ="button" type="button" value="5" onclick="insert(5)"></td>
<td><input class ="button" type="button" value="6" onclick="insert(6)"></td>
<td><input class ="button" type="button" value="+" onclick="insert('+')"></td>
</tr>
<tr>
<td><input class ="button" type="button" value="1" onclick="insert(1)"></td>
<td><input class ="button" type="button" value="2" onclick="insert(2)"></td>
<td><input class ="button" type="button" value="3" onclick="insert(3)"></td>
<td rowspan="2"><input class ="button" type="button" value="=" onclick="equal()"></td>
</tr>
<tr>
<td colspan="2"><input class ="button" type="button" value="0" onclick="insert(0)"></td>
<td><input class ="button" type="button" value="." onclick="insert('.')"></td>
</tr>
</table>
</div>
<script src="main.js">
</script>
</body>
</html>
20 changes: 20 additions & 0 deletions Week1/homework/js calculator/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
function insert(num){
document.form.textview.value = document.form.textview.value+num
}

function equal(){
var exp = document.form.textview.value

if(exp){ document.form.textview.value = eval(exp)
}
}
function clean(){
document.form.textview.value = ""
}

function back(){
var exp = document.form.textview.value

document.form.textview.value = exp.substring(0,exp.length-1)
}

15 changes: 15 additions & 0 deletions Week1/homework/js-exercises/10_compareArrays.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use strict'

//Declare 2 variables, that each hold an array. The first array should have 4 items, the second 7 items
const array1=["one",1,true,{name:"array1"}];
const array2=["one",2,3,"four","five",6,7];

//Find out how to get the length of each array. Write a console.log statement that shows the length of each array
console.log("Array1 has length of "+ array1.length);
console.log("Array2 has length of "+ array2.length);

//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
if(array1==array2){
console.log("They are the same!");
}
else console.log("Two different sizes");
11 changes: 11 additions & 0 deletions Week1/homework/js-exercises/1_logHello.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict'
console.log("Hello, World!")
console.log("Geia sou, Kosme!")
console.log("Ciao, Mondo!")
console.log("Bonjour, le Monde!")
console.log("Hallo, Welt!")
console.log("Hola, Mundo!")
console.log("Hei, Verden!")
console.log("salve, Mundi!")
console.log("Selam, Dunya!")
console.log("Witaj, Wiecie!")
2 changes: 2 additions & 0 deletions Week1/homework/js-exercises/2_ErrorDebugging.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
'use strict'
console.log("I'm Awesome")
18 changes: 18 additions & 0 deletions Week1/homework/js-exercises/3_LogNumber.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict'
/*First, declare your variable numberX. Do not initialize it (which means, don't give it a value) yet.*/
var numberX

/*Add a console.log statement that explains in words what you think the value of x is, like in this example.*/
console.log("The value of the numberX is null")

/*Add a console.log statement that logs the value of numberX.*/
console.log(numberX)

/*Now initialize your variable numberX with a number (also called an integer in computer science terms).*/
numberX=5

/*Next, add a console.log statement that explains what you think the value of numberX is.*/
console.log("Now the numberX has a value")

/*Add a console.log statement that logs the value of numberX.*/
console.log(numberX)
18 changes: 18 additions & 0 deletions Week1/homework/js-exercises/4_LogString.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict'
/*Declare a variable myString and assign a string to it. Use your full name, including spaces, as the content for the string.*/
let myString="Kiriakos Mouzakis";

/*Write a console.log statement in which you explain in words what you think the value of the string is.*/
console.log("The value of myString is my full name");

/*Now console.log the variable myString.*/
console.log(myString);

/*Now reassign to the variable myString a new string.*/
myString=("Now I am Batman");

/*Just like what you did before write a console.log statement that explains in words what you think will be logged to the console.*/
console.log("Now the string has changed");

/*Now console.log myString again.*/
console.log(myString);
23 changes: 23 additions & 0 deletions Week1/homework/js-exercises/5_RndNum.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict'
/*Declare a variable z and assign the number 7.25 to it.*/
let z=7.25;

/*Write a console.log statement in which you log the value of z.*/
console.log("'Z' value is "+z);

/*Declare another variable a that has the value of z but rounded to the nearest integer.*/
let a;
a=Math.round(z);

/*Write a console.log statement in which you log the value of a.*/
console.log("'A' has the same value but is rounded "+a);

/*So now we have z and a find a way to compare the two values and store the highest of the two in a new variable. */
/*Write a console.log statement in which you log the value of the highest value.*/
function bigger(){
if(a>z) {console.log("'A' is bigger with value of "+a)
}
else {console.log("'Z' is bigger with value of "+z)
}
}
bigger()
23 changes: 23 additions & 0 deletions Week1/homework/js-exercises/6_arrayAnimals.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict'
/*Declare variable and assign to it an empty array.
Make sure that the name of the variable indicates it contains more than 1 item. For example items instead of item.*/
let array1=new Array;

/*Write a console.log statement that explains in words what you think the value of the array is.*/
console.log("The value of the array is empty")

/*Write a console.log statement that logs the array.*/
console.log(array1);

/*Create a new variable with an array that has 3 of your favorite animals, each in a different string.
Make sure the name of the variables says something about what the variable contains.*/
let animals=["lion","tiger","panther"];

/*Write a console.log statement that logs the second array.*/
console.log(animals);

/*Add a statement that adds another string ("Piglet)" to the array of animals.*/
animals.push("Piglet");

/*Write a console.log statement that logs the second array!*/
console.log(animals);
9 changes: 9 additions & 0 deletions Week1/homework/js-exercises/7_stringLength.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use strict'
/*/Declare a variable called mySentence and initialize it with the following string: "Programming is so interesting!".*/
let mySentence="Programming is so interesting!";

/*Figure out (using Google) how to get the length of mySentence.*/
let stringLength=mySentence.length;

/*Write a console.log statement to log the length of mySentence.*/
console.log(stringLength);
37 changes: 37 additions & 0 deletions Week1/homework/js-exercises/8_typeChecker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
'use strict'
/*Write a program that checks the data types of two variables and logs to the console SAME TYPE if they are the same type.
If they are different types log Not the same....*/
/*Declare 4 variables: 2 must be strings and 2 must be objects*/
let string1="social";
let string2="hackers";
let fname={firstname:"kiriakos"};
let lname={lastname:"mouzakis"};

/*Create 6 conditional statements, where for each you check if the data type of one variable is the same as the other*/
if (typeof string1 === typeof string2) {console.log("string1 and string2 are the same type");}
if (typeof string1 === typeof fname) {console.log("string1 and fname are the same type");}
if (typeof string1 === typeof lname) {console.log("string1 and lname are the same type");}
if (typeof string2 === typeof fname) {console.log("string2 and fname are the same type");}
if (typeof string2 === typeof lname) {console.log("string2 and lname are the same type");}
if (typeof fname === typeof lname) {console.log("fname and lname are the same type");}

/*Find out how to check the type of a variable*/
console.log("You can check a type of a variable with the typeof() command eg.. The type of fname is an "+typeof fname);

/*Write 2 console.log statements to log the type of 2 variables, each with a different data type*/
console.log(typeof(string1));
console.log(typeof(lname));

/*Now compare the types of your different variables with one another*/
/*Log Not the same... when the types are different*/
let num1=1;
if (typeof string1 === typeof string2) {console.log("string1 and string2 are the same type")} else {console.log("Not the same type"); }
if (typeof string1 === typeof fname) {console.log("string1 and fname are the same type");} else {console.log("Not the same type"); }
if (typeof string1 === typeof lname) {console.log("string1 and lname are the same type");} else {console.log("Not the same type"); }
if (typeof string2 === typeof fname) {console.log("string2 and fname are the same type");} else {console.log("Not the same type"); }
if (typeof string2 === typeof lname) {console.log("string2 and lname are the same type");} else {console.log("Not the same type"); }
if (typeof fname === typeof lname) {console.log("fname and lname are the same type");} else {console.log("Not the same type"); }
if (typeof num1 === typeof string1) {console.log("num1 and string1 are the same type");} else {console.log("Not the same type"); }
if (typeof num1 === typeof string2) {console.log("num1 and string2 are the same type");} else {console.log("Not the same type"); }
if (typeof num1 === typeof fname) {console.log("num1 and fname are the same type");} else {console.log("Not the same type"); }
if (typeof num1 === typeof lname) {console.log("num1 and lname are the same type");} else {console.log("Not the same type"); }
9 changes: 9 additions & 0 deletions Week1/homework/js-exercises/9_remainder.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use strict'
/*For each of these, write in comments what the answer is followed by how you came to that conclusion*/

/*If x equals 7, and the only other statement is x = x % 3, what would be the value of x after the calculation?*/
console.log("At first x will have the value 7, then after the division it will take the value of the modulus (% symbol) and will be 1");
/*If y equals 21, and the only other statement is y = y % 4, what would be the value of y after the calculation?*/
console.log("At first y will have the value 21, then after the division it will take the value of the modulus (% symbol) and will be 1");
/*If z equals 13, and the only other statement is z = z % 2, what would be the value of z after the calculation?*/
console.log("At first z will have the value 13, then after the division it will take the value of the modulus (% symbol) and will be 1");
13 changes: 13 additions & 0 deletions Week2/homework/js1_week2_exercises/1_removeComma.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict'
/*let myString = "hello,this,is,a,difficult,to,read,sentence";
Add the variable to your file.*/
let myString = "hello,this,is,a,difficult,to,read,sentence"

//Log the length of myString.
console.log(myString.length);

//The commas make that the sentence is quite hard to read. Find a way to remove the commas from the string and replace them with spaces. (use Google!)
let newString=myString.replace(/,/g,' ');

//After replacing the commas, log myString to see if you succeeded.
console.log(newString);
12 changes: 12 additions & 0 deletions Week2/homework/js1_week2_exercises/2_oddEven.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use strict'
/*Report whether or not a number is odd/even!
Create a for loop, that iterates from 0 to 20.*/

for(let i=0; i<21; i++){
/*Create a conditional statement that checks if the value of the counter variable is odd or even.
If it's odd, log to the console The number [PUT_NUMBER_HERE] is odd!.
If it's even, log to the console The number [PUT_NUMBER_HERE] is even!.*/
if(i%2) {
console.log("The number "+i+" is odd.");
}
else console.log("The number "+i+" is even.");}
18 changes: 18 additions & 0 deletions Week2/homework/js1_week2_exercises/3_recipeCard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict'
/*Ever wondered how to make a certain meal? Let's create a recipe list with JavaScript!
Declare a variable that holds an object (your meal recipe).*/
//Give the object 3 properties: a title (string), a servings (number) and an ingredients (array of strings) property.
const tost={
Title:"Tost",
Servings:1,
Ingredients:["Slices of bread","cheese","ham","tomato"]
}
//Log each property out seperately, using a loop (for, while or do/while)

let recipe=[tost]

for (let i of recipe){
console.log("Title: "+i.Title);
console.log("Servings: "+i.Servings);
console.log("Ingredients: "+"\n"+i.Ingredients[0]+"\n"+i.Ingredients[1]+"\n"+i.Ingredients[2]+"\n"+i.Ingredients[3]);
}
40 changes: 40 additions & 0 deletions Week2/homework/js1_week2_exercises/4_readingList.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
'use strict'
/*Keep track of which books you read and which books you want to read!
Declare a variable that holds an array of 3 objects, where each object describes a book and
has properties for the title (string), author (string), and alreadyRead (boolean indicating if you read it yet).*/
const lord_of_the_rings={
title:"The Fellowship of the Ring",
author:"J. R. R. Tolkien",
alreadyRead:false
}
const game_of_thrones={
title:"A Song of Ice and Fire",
author:"George R. R. Martin",
alreadyRead:true
}
const harry_potter={
title:"The Philosopher's Stone",
author:"J. K. Rowling",
alreadyRead:true
}
//Loop through the array of books.
var myBooks=[lord_of_the_rings,game_of_thrones,harry_potter];

myBooks.forEach(item=> console.log(item));

//For each book, log the book title and book author like so: "The Hobbit by J.R.R. Tolkien".
myBooks.forEach(item=> {
return console.log(item.title + " by " + item.author+ "\n");
});

/*Create a conditional statement to change the log depending on whether you read it yet or not.
If you read it, log a string like You already read "The Hobbit" right after the log of the book details
If you haven't read it log a string like You still need to read "The Lord of the Rings"*/
for (let item of myBooks){
if (item.alreadyRead == true){

console.log("You already read: " + item.title + "\n");
}else{
console.log("You still nead to read: "+ item.title + "\n");
}
}
21 changes: 21 additions & 0 deletions Week2/homework/js1_week2_exercises/5_drinkTray.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict'
//You're at a party and you feel thirsty! However, you've got 5 friends who are also in need of a drink. Let's go get them a drink.
//Declare a variable that holds an empty array, called drinkTray.
let drinkTray=new Array(5);

//There are 3 different types of drinks:
//const drinkTypes = ["cola", "lemonade", "water"];
const drinkTypes = ["cola", "lemonade", "water"];

/*Create a loop that runs 5 times. On each iteration, push a drink into the drinkTray variable.
The drinkTray can only hold at most two instances of the same drink type, for example it can only hold 2 colas, 2 lemonades, 2 waters.
If there are already two instances of a drinkType then start with the next drink in the array.
Your drinkTray should contain 2 cola, 2 lemonade and 1 water.*/
let x = 0;
for (let i = 0; i < 5; i++){
drinkTray[i] = drinkTypes[x];
if(i%2 == 1) x++;
}

//Log to the console: "Hey guys, I brought a [INSERT VALUES FROM ARRAY]!" (For example: "Hey guys, I brought a cola, cola, lemonade, lemonade, water!")
console.log("Hey guys, I brought a " + drinkTray.join()+".");
Loading