Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
finished project for homework week2,JS1
  • Loading branch information
ERodias committed Jan 25, 2020
commit a3a66003d283cfc23a6c21f478aff03879d2ac48
Empty file.
63 changes: 63 additions & 0 deletions Week2/homework/JS Exercises/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
//-----------Exercise 1: Remove the comma--------------
let myString = "hello,this,is,a,difficult,to,read,sentence";
console.log(myString.length);
var noCommasString = myString.split(',').join(" ");
myString=noCommasString;
console.log(myString);

//-----------Exercise 2: The even/odd reporter--------------
for (var num=0; num<20; num++){
if (num % 2==0) {
console.log("The number "+ num + " is even!")
}
if (num % 2!==0){
console.log("The number "+ num + " is odd!")
}
}

//-----------Exercise 3: The recipe card--------------
let recipe={Meal_name: "Omelete", Serves: 2,
Ingredients: ["4 eggs", "2 strips of bacon", "1 tsp salt/pepper"]};

for (name in recipe){
if (name=="Ingredients"){
console.log("Ingredients:");
} else {
console.log(name +": " + recipe[name]);
}
}

for (j=0; j<3;j++){
console.log(recipe.Ingredients[j]);
}

//-----------Exercise 4: The reading list--------------
let bookArray=[{ title: "The Hobbit", author: "J.R.R. Tolkien", alreadyRead:true},
{title: "The Lord of the Rings", author: "J.R.R. Tolkien", alreadyRead:false},
{title: "The Last of the Mohicans", author: "J.F. Cooper", alreadyRead:true}];

bookArray.forEach(function(element){console.log(element.title + " by " + element.author)});

bookArray.forEach(function(element){
if (element.alreadyRead==true){
console.log("You already read " + element.title)
} else {
console.log("You still need to read " + element.title)
}
});

//-----------Exercise 5: Who wants a drink?--------------

var drinkTray=[];
const drinkTypes = ["cola", "lemonade", "water"];
for (i=0;i<5;i++){
for (j=0;j<drinkTypes.length; j++){
drinkTray.push(drinkTypes[j])
if (drinkTray.length===5){
console.log( "Hey guys, I brought a "+ drinkTray.sort() +"!")
break;
}
}
}


16 changes: 16 additions & 0 deletions Week2/homework/Project (Grade calculator)/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>

<script src="main.js">

</script>
</body>
</html>
24 changes: 24 additions & 0 deletions Week2/homework/Project (Grade calculator)/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const num=91; // this is the grade as a number

function scoreCalc(a){ //this function will assign the score to its class
if (a>=0 && a<=49){
gradeClass="F";
} else if (a>49 && a<60){
gradeClass="E";
} else if (a>59 && a<70){
gradeClass="D";
} else if (a>69 && a<80){
gradeClass="C";
} else if (a>79 && a<90){
gradeClass="B";
} else if (a>89 && a<=100){
gradeClass="A";
} else {
gradeClass="INVALID GRADE";
}
return result= `You got a ${gradeClass} (${num}%)!`;
}

gradePct=scoreCalc(num);
console.log(gradePct);