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

<button id="list">BUY</button>
<h3 id="demo"></h3>

<script>
const drinkTypes = ['cola', 'lemonade', 'water'];
const drinkTray = [];

function tray() {
var list = "";
var i;
for (i = 0; i < 5; i++) {
var rand = Math.floor(Math.random() * drinkTypes.length);
drinkTray.push(drinkTypes[rand])
//if (drinkTray.includes(drinkTypes[rand])){
//delete drinkTypes[rand];
//}
drinkTray.sort();
}
return drinkTray;
}
document.getElementById("list").addEventListener("click", function() {
document.getElementById("demo").innerHTML = "Hey guys, I brought a " + tray() +"!";
});
</script>
</body>
</html>
36 changes: 36 additions & 0 deletions ReadingList.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>

<button id="list">LIST</button>
<h5 id="demo"></h5>

<script>
const a = ['The Da Vinci Code','Dan Brown',0];
const b = ['Harry Potter and the Deathly Hallows', 'J.K. Rowling',1];
const c = ['One Day', 'David Nicholls',0];
const d = ['Life of Pi','Yann Martel',1];
const bookList = [a,b,c,d];

function viewBook() {
var list = "";
var x;
for (x in bookList) {
list += bookList[x][0] + ' by ' +bookList[x][1] + "<br>";
if (bookList[x][2]==0 ) {
list += "You still need to read '" + bookList[x][0] + "'. <br>";
} else {
list += "You already read '" + bookList[x][0] + "'. <br>";
}
}
return list
}
document.getElementById("list").addEventListener("click", function() {
document.getElementById("demo").innerHTML = viewBook();
});
</script>
</body>
</html>
31 changes: 31 additions & 0 deletions TotalPrice.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>

<button id="buy">BUY</button>
<h1 id="demo"></h1>

<script>
const cartForParty = {Banana:1.15, Apple:0.95, Kiwi:2.25};

function addToShoppingCart() {
var total = 0;
var list = "";
var x;
for (x in cartForParty) {
list += x +" : " + cartForParty[x] + "<br>" ;
total += cartForParty[x];
}
list +='-----------------<br>' + 'Total : ' + total;
return list
}

document.getElementById("buy").addEventListener("click", function() {
document.getElementById("demo").innerHTML = addToShoppingCart();
});
</script>
</body>
</html>
41 changes: 41 additions & 0 deletions shoppingCart.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
Add to Cart: <input type="text" id="myText">
<button id='add'>ADD</button> <br>

<button id="buy">BUY</button>
<h1 id="demo"></h1>

<script>
const shoppingCart = ['bananas', 'milk'];

function addToShoppingCart() {
var item = document.getElementById("myText").value;
shoppingCart.push(item)
if (shoppingCart.length>3) {
shoppingCart.shift();
}
}

function buylist() {
var shopingList = "You bought ";
var i;
for (i = 0; i < shoppingCart.length; i++) {
shopingList += shoppingCart[i] + ", ";
}
return shopingList;
}

document.getElementById("add").addEventListener("click", function() {
addToShoppingCart()});

document.getElementById("buy").addEventListener("click", function() {
document.getElementById("demo").innerHTML = buylist();
});
</script>
</body>
</html>
39 changes: 39 additions & 0 deletions tellFortune.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<!DOCTYPE html>
<html>
<body>

<button id="myBtn">Try it</button>
<h1 id="demo"></h1>

<script>
const numChildren = [0,1,2] ;
const partnerNames = ["Nick","Peter","Frank","Anne"] ;
const locations = ["France","England","Germany","Seweden"];
const jobs = ["Teacher","Datascientist","Engnery","Freelancer"];

function tellFortune() {
var rand = Math.floor(Math.random() * partnerNames.length);
var print ='You are married with ' + partnerNames[rand];
rand = Math.floor(Math.random() * numChildren.length);
if (rand == 0) {
print += " and you don't have childeren. ";
} else if (rand == 1) {
print += " and you have " + numChildren[rand] + " child.";
} else {
print += " and you have " + numChildren[rand] + " children.";
}
rand = Math.floor(Math.random() * locations.length);
print += " You live in " + locations[rand];
rand = Math.floor(Math.random() * jobs.length);
print += " and you work as a " + jobs[rand] + ".";
return print;
}

document.getElementById("myBtn").addEventListener("click", function() {
document.getElementById("demo").innerHTML = tellFortune();
});
</script>

</body>
</html>