Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0c60e50

Browse files
Add files via upload
1 parent d547591 commit 0c60e50

File tree

6 files changed

+69
-0
lines changed

6 files changed

+69
-0
lines changed

Week2/homework/js-exercises/aDrink.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
'use strict';
2+
3+
let drinkTray = [];
4+
5+
const drinkTypes = [" cola", " lemonade", " water"];
6+
7+
let index = drinkTypes.length;
8+
while(index < 5){
9+
drinkTray.push(drinkTypes);
10+
index++;
11+
}
12+
console.log("Hey guys, I brought a " + drinkTray);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
'use strict';
2+
3+
for (let number = 0; number <= 20; number++) {
4+
if(number%2 == 1)
5+
console.log('the number '+number+' is odd!');
6+
else
7+
console.log('the number '+number+' is even!');
8+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
'use strict';
2+
3+
//this function calculates grades based on the American grading system and converts the score into a percentage.
4+
5+
function gradeCalculator(score){
6+
if(score >= 90 && score <= 100 ){
7+
// %d or %i are used for numbers to show the score values in the strings.
8+
console.log("You got a A (%d%)!",score);
9+
}else if(score >= 80 && score <= 89){
10+
console.log("You got a B (%i%)!",score);
11+
}else if(score >= 70 && score <= 79){
12+
console.log("You got a C (%d%)!",score);
13+
}else if(score >= 60 && score <= 69){
14+
console.log("You got a D (%i%)!",score);
15+
}else if(score >= 50 && score <= 59){
16+
console.log("You got a E (%d%)!",score);
17+
}else if(score >= 0 && score <= 49){
18+
console.log("You got a F (%i%)!",score);
19+
}
20+
}
21+
22+
gradeCalculator(49);
23+
gradeCalculator(94);
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
'use strict';
2+
3+
let books = [
4+
{ title: "Harry Potter 1", author: "J. K. Rowling", alreadyRead: true },
5+
{ title: "Harry Potter 2", author: "J. K. Rowling", alreadyRead: true },
6+
{ title: "Harry Potter 3", author: "J. K. Rowling", alreadyRead: false }
7+
];
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
'use strict';
2+
let recipe = {
3+
title: 'Omelette',
4+
servings: 2,
5+
ingredients: ['4 eggs', '2 strips of bacon', '1 tsp salt/pepper']
6+
}
7+
8+
for () {
9+
10+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
'use strict';
2+
3+
let myString = "hello,this,is,a,difficult,to,read,sentence";
4+
5+
console.log(myString.length);
6+
7+
let myNewString = myString.replace(/,/g , " ");
8+
9+
console.log(myNewString);

0 commit comments

Comments
 (0)