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
44 changes: 44 additions & 0 deletions JS_week1_exercise9.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<!DOCTYPE html>
<html>
<head>

</head>
<body>

<!-- After we define the variables and give the initial values, we assign another value to each variable based on
the second equality. So, the value of each variable changes according to the second line of code. The equality calculates
the remainder of each variable with the % symbol and the result for each is equal to 1 as shown in the HTML file.-->

<p>The value of x:</p>
<p id="demo1"></p>
<hr/>

<p>The value of y:</p>
<p id="demo2"></p>
<hr/>

<p>The value of z:</p>
<p id="demo3"></p>

<script type="text/javascript">

var x = 7;
x = x % 3;
document.getElementById("demo1").innerHTML = x;


var y = 21;
y = y % 4;
document.getElementById("demo2").innerHTML = y;

var z = 13;
z = z % 2;
document.getElementById("demo3").innerHTML = z;

</script>




</body>
</html>
47 changes: 47 additions & 0 deletions JS_week2_exercise4.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<!DOCTYPE html>
<html>
<head>

</head>
<body>

<p id="demo"></p>

<script type="text/javascript">

function book (title, author, alreadyRead)
{
this.title = title;
this.author = author;
this.alreadyRead = alreadyRead
}

var book1 = new book("War & Peace", "Leo Tolstoy", true);
var book2 = new book("Leo Africanus", "Amin Maalouf", false);
var book3 = new book("Angels and Demons", "Dan Brown", false);

var books = [book1, book2, book3];

var text = "";

for (var i=0; i<books.length; i++)
{
text += books[i].title+" by "+books[i].author+"<br>";
if (books[i].alreadyRead==true)
{
text += "You already read "+books[i].title+"<hr>";
}
else
{
text += "You still need to read "+books[i].title+"<hr>";
}
}
document.getElementById("demo").innerHTML = text;

</script>




</body>
</html>
41 changes: 41 additions & 0 deletions JS_week2_exercise5.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!DOCTYPE html>
<html>
<head>

</head>
<body>

<p id="demo"></p>

<script type="text/javascript">

const drinkTray = new Array();
const drinkTypes = ['cola', 'lemonade', 'water'];
text = "";

for (var i=0; i<5; i++)
{
if (drinkTray.length<2)
{drinkTray.push(drinkTypes[0]);}
else
{
if (drinkTray.length<4)
{
drinkTray.push(drinkTypes[1]);
}
else
{
drinkTray.push(drinkTypes[2]);
}
}
}

document.getElementById("demo").innerHTML = "Hey guys, I brought "+drinkTray+"!";

</script>




</body>
</html>
31 changes: 31 additions & 0 deletions JS_week3_exercise3.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!DOCTYPE html>
<html>
<head>

</head>
<body>

<p id="demo"></p>

<script type="text/javascript">

const numChildren = [1, 2, 3, 4, 5];
const partnerNames = ["Adam", "Joe", "Barry", "Jack", "Phil"];
const locations = ["Netherlands", "USA", "Germany", "UK", "Canada"];
const jobs = ["teacher", "professor", "data scientist", "manager", "sales representative"];
var text = "";

function tellFortune (children, partner, location, job)
{
document.getElementById("demo").innerHTML = text+"You will be a "+job[Math.floor(Math.random() * 5)]+" in "+location[Math.floor(Math.random() * 5)]+ ", married to "+partner[Math.floor(Math.random() * 5)]+" with "+children[Math.floor(Math.random() * 5)]+" kid(s).";
}

tellFortune(numChildren, partnerNames, locations, jobs);

</script>




</body>
</html>
49 changes: 49 additions & 0 deletions JS_week3_exercise4.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<!DOCTYPE html>
<html>
<head>

</head>
<body>

<p id="demo"></p>

<script type="text/javascript">

const shoppingCart = ['bananas', 'milk'];
text = "";

function addToShoppingCart (item)
{ shoppingCart.push(item);
if (shoppingCart.length>=4)
{
shoppingCart.shift();

for (var i=0; i<shoppingCart.length; i++)
{
text += shoppingCart[i]+ ", ";
}
document.getElementById("demo").innerHTML = "You bought "+shoppingCart+ "!";

}
else
{
for (var i=0; i<shoppingCart.length; i++)
{
text += shoppingCart[i]+ ", ";
}
document.getElementById("demo").innerHTML = "You bought "+shoppingCart+ "!";
}
}

addToShoppingCart('chocolate');
// addToShoppingCart('waffles');
// addToShoppingCart('tea');


</script>




</body>
</html>
32 changes: 32 additions & 0 deletions JS_week3_exercise5.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!DOCTYPE html>
<html>
<head>

</head>
<body>

<p id="demo"></p>

<script type="text/javascript">

const cartForParty = {"beer":1.75, "chips":0.99, "coke":1.01, "nuts":4.25, "cookies":2.75}
sum = 0;


function calculateTotalPrice(items)
{
sum = items.beer+items.chips+items.coke+items.nuts+items.cookies;
document.getElementById("demo").innerHTML = "Total: €"+sum;

}


calculateTotalPrice(cartForParty);

</script>




</body>
</html>