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

Skip to content
This repository was archived by the owner on May 14, 2024. It is now read-only.

Commit 8a75374

Browse files
committed
week2
1 parent 7d57c0c commit 8a75374

File tree

6 files changed

+127
-0
lines changed

6 files changed

+127
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
'use strict'
2+
// Create a for loop, that iterates from 0 to 20.
3+
// Create a conditional statement that checks if the value of the counter variable is odd or even.
4+
// If it's odd, log to the console The number [PUT_NUMBER_HERE] is odd!.
5+
// If it's even, log to the console The number [PUT_NUMBER_HERE] is even!.
6+
7+
for(let i=0; i<20; i++) {
8+
if (i%2===0) {
9+
console.log("The number "+i+ " is even!.");
10+
} else {
11+
console.log("The number "+i+ " is odd!.");
12+
}
13+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
'use strict'
2+
// convert the score into a percentage
3+
// calculate what grade corresponds with that percentage, and
4+
// shows in the command line the result: the grade and the percentage
5+
// When writing the script, make use of the following grade scores:
6+
// Grade A (90% - 100%)
7+
// Grade B (80% - 89%)
8+
// Grade C (70% - 79%)
9+
// Grade D (60% - 69%)
10+
// Grade E (50% - 59%)
11+
// Grade F (0% - 49%)
12+
13+
14+
function gradeCalculator(score) {
15+
//To be able to show the result of decimal number I used here Math.round.
16+
score = Math.round(score);
17+
let grade;
18+
//I use switch by evaluating true statement.
19+
switch(true) {
20+
case (score <= 100 && score >= 90):
21+
grade = 'A';
22+
break;
23+
case (score <= 89 && score >= 80):
24+
grade = 'B';
25+
break;
26+
case (score <= 79 && score >= 70):
27+
grade = 'C';
28+
break;
29+
case (score <= 69 && score >= 60):
30+
grade = 'D';
31+
break;
32+
case (score <= 59 && score >= 50):
33+
grade = 'E';
34+
break;
35+
case (score <= 49 && score >= 0):
36+
grade = 'F';
37+
break;
38+
default:
39+
console.log("You got a INVALID SCORE");
40+
}
41+
return ("You got a " +grade+ " (" +score+ "%)!");
42+
};
43+
console.log(gradeCalculator(1));
44+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
'use strict'
2+
// 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).
3+
// Loop through the array of books.
4+
// For each book, log the book title and book author like so: "The Hobbit by J.R.R. Tolkien".
5+
// 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
6+
// If you haven't read it log a string like You still need to read "The Lord of the Rings"
7+
8+
let books = [{title:"1984", author:"George Orwell", alreadyRead:false},
9+
{title:"Improbable", author:"Adam Fawer", alreadyRead:true},
10+
{title:"The Da Vinci Code", author:"Dan Brown", alreadyRead:true}];
11+
12+
for (var i = 0; i < books.length; i++) {
13+
console.log(books[i].title +" by "+ books[i].author );
14+
if(books[i].alreadyRead===true){
15+
console.log("You already read "+ books[i].title);
16+
}else {
17+
console.log("You still need to read "+ books[i].title);
18+
}
19+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
'use strict'
2+
// Declare a variable that holds an object (your meal recipe).
3+
// Give the object 3 properties: a title (string), a servings (number) and an ingredients (array of strings) property.
4+
// Log each property out seperately, using a loop (for, while or do/while)
5+
6+
const myBreakfastRecipe = {
7+
mealName: "Atom",
8+
serves: 2,
9+
ingredients: ["100g outmeal", "One babana", "100g milk"]
10+
};
11+
12+
//to write ingredients in the same line
13+
// for (const property in myBreakfastRecipe) {
14+
// console.log(`${property}: ${myBreakfastRecipe[property]}`);
15+
// }
16+
17+
for (const property in myBreakfastRecipe) {
18+
if(typeof myBreakfastRecipe[property]==="object"){
19+
console.log(property+":");
20+
for (let ing of myBreakfastRecipe[property]){
21+
console.log(ing+",")
22+
}
23+
} else {
24+
console.log(property+": "+myBreakfastRecipe[property] )
25+
}
26+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
'use strict'
2+
// let myString = 'hello,this,is,a,difficult,to,read,sentence';
3+
// Add the variable to your file.
4+
// Log the length of myString.
5+
// 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!)
6+
// After replacing the commas, log myString to see if you succeeded.
7+
8+
let myString = 'hello,this,is,a,difficult,to,read,sentence';
9+
console.log(myString.length);
10+
myString = myString.replace(/,/g," ");
11+
console.log(myString);
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
'use strict'
2+
// Declare a variable that holds an empty array, called drinkTray.
3+
// There are 3 different types of drinks:
4+
// 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.
5+
// If there are already two instances of a drinkType then start with the next drink in the array.
6+
// Your drinkTray should contain 2 cola, 2 lemonade and 1 water.
7+
// 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!")
8+
9+
let drinkTray= [];
10+
const drinkTypes = ['cola', 'lemonade', 'water'];
11+
for (let i = 0; i < 5; i++) {
12+
drinkTray.push(drinkTypes[i%3])
13+
}
14+
console.log("Hey guys, I brought a "+ drinkTray.join(', ')+"!");

0 commit comments

Comments
 (0)