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.

Created exercise templates #278

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
23 changes: 23 additions & 0 deletions Week1/exercise01.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict'

/*

Exercise 1: Hello world!

Write a statement, using the console.log() function. It should fulfill the following requirements:

It takes a string as an argument
The string should contain the message "Hello world!"
Execute the function 10 times, each time using the phrase in different languages
For example:

Halo, dunia! // Indonesian
Ciao, mondo! // Italian
Hola, mundo! // Spanish
Finished? Using the command line, navigate to your js-exercises folder and type in the following to test your code:

foo@bar:~$ node exercise01.js
Expected output: It should show the message Hello world! in 10 different languages.

*/

21 changes: 21 additions & 0 deletions Week1/exercise02.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict'

/*

Exercise 2: Error debugging

Consider the following code:

console.log('I'm awesome'!;
Here are the requirements:

Copy the code in your .js file and run it in the command line using node.
You will see that you will get a SyntaxError.

Correct the mistake.
Hint: the SyntaxError message will give you some indication of what the error might be, but figure out yourself how to correct it!

Expected output: When done right, the command line should show the message I'm awesome!.

*/

17 changes: 17 additions & 0 deletions Week1/exercise03.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'use strict'

/*

Exercise 3: Log the number

Follow the steps. Make sure that each step is written on the line after.

First, declare your variable numberX. Do not initialize it (which means, don't give it a starting value) yet
Add a console.log statement that explains in words what you think the value of x is
Add a console.log statement that logs the value of numberX.
Now initialize your variable numberX with a number (also called an integer in computer science terms)
Next, add a console.log statement that explains what you think the value of numberX is
Add a console.log statement that logs the value of numberX

*/

17 changes: 17 additions & 0 deletions Week1/exercise04.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'use strict'

/*

Exercise 4: Log the string

Follow the steps. Make sure that each step is written on the line after.

Declare a variable myString and assign a string to it. Use your full name, including spaces, as the content for the string.
Write a console.log statement in which you explain in words what you think the value of the string is.
Now console.log the variable myString.
Now reassign to the variable myString a new string.
Just like what you did before write a console.log statement that explains in words what you think will be logged to the console.
Now console.log myString again.

*/

17 changes: 17 additions & 0 deletions Week1/exercise05.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'use strict'

/*

Exercise 5: Round a number and log it

Follow the steps. Make sure that each step is written on the line after.

Declare a variable z and assign the number 7.25 to it.
Write a console.log statement in which you log the value of z.
Declare another variable a that has the value of z but rounded to the nearest integer.
Write a console.log statement in which you log the value of a.
So now we have z and a find a way to compare the two values and store the highest of the two in a new variable.
Write a console.log statement in which you log the value of the highest value.

*/

18 changes: 18 additions & 0 deletions Week1/exercise06.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict'

/*

Exercise 6: Log an array of animals

Follow the steps. Make sure that each step is written on the line after.

Declare variable and assign to it an empty array. Make sure that the name of the variable indicates it contains more than 1 item. For example items instead of item.
Write a console.log statement that explains in words what you think the value of the array is.
Write a console.log statement that logs the array.
Create a new variable with an array that has 3 of your favorite animals, each in a different string. Make sure the name of the variables says something about what the variable contains.
Write a console.log statement that logs the second array.
Add a statement that adds another string ("Piglet)" to the array of animals.
Write a console.log statement that logs the second array!

*/

14 changes: 14 additions & 0 deletions Week1/exercise07.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use strict'

/*

Exercise 7: Log the length of a string

Follow the steps. Make sure that each step is written on the line after.

Declare a variable called mySentence and initialize it with the following string: "Programming is so interesting!".
Figure out (using Google) how to get the length of mySentence.
Write a console.log statement to log the length of mySentence.

*/

36 changes: 36 additions & 0 deletions Week1/exercise08.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
'use strict'

/*

Exercise 8: Type checker

Create a function that fulfills the following requirements:

Takes in 2 arguments
Check the data type of each
Compares each data type
Logs to the console the message SAME TYPE if they are the same type. If they are different types log Not the same....
Follow the steps:

Declare 4 variables: 2 must be strings and 2 must be objects
Create 6 conditional statements, where for each you check if the data type of one variable is the same as the other
Find out how to check the type of a variable
Write 2 console.log statements to log the type of 2 variables, each with a different data type
Now compare the types of your different variables with one another
Log Not the same... when the types are different
Here's an incomplete example of how it could look:

// Declare all variables
let x = 9;
let y = 67;

// Check data type
console.log(...);

// Check if data type is the same
if (...) {
console.log('SAME TYPE');
}

*/

14 changes: 14 additions & 0 deletions Week1/exercise09.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
'use strict'

/*

Exercise 9: Log the remainder

Answer the following questions. For each, write in comments what the answer is followed by how you came to that conclusion:

If x equals 7, and the only other statement is x = x % 3, what would be the value of x after the calculation?
If y equals 21, and the only other statement is y = y % 4, what would be the value of y after the calculation?
If z equals 13, and the only other statement is z = z % 2, what would be the value of z after the calculation?

*/

17 changes: 17 additions & 0 deletions Week1/exercise10.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'use strict'

/*

Exercise 10: Compare arrays

Follow the steps:

Declare 2 variables, that each hold an array. The first array should have 4 items, the second 7 items
Find out how to get the length of each array. Write a console.log statement that shows the length of each array
const array = ["hello", 123, true, { name: "Noer" }];

console.log('The length of the array is...' + ...);
Write a conditional statement that checks if both are of equal length. If they are, log to the console They are the same!, if not log Two different sizes

*/

19 changes: 19 additions & 0 deletions Week2/exercise01.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'use strict'

/*

Exercise 1: Remove the comma

Consider the following string:

let myString = 'hello,this,is,a,difficult,to,read,sentence';
Follow the steps:

Add the variable to your file.
Log the length of myString.
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!)
After replacing the commas, log myString to see if you succeeded.
Expected result in the console: hello this is a difficult to read sentence

*/

15 changes: 15 additions & 0 deletions Week2/exercise02.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use strict'

/*

Exercise 2: The even/odd reporter

Report whether or not a number is odd/even!

Create a for loop, that iterates from 0 to 20.
Create a conditional statement that checks if the value of the counter variable is odd or even.
If it's odd, log to the console The number [PUT_NUMBER_HERE] is odd!.
If it's even, log to the console The number [PUT_NUMBER_HERE] is even!.

*/

19 changes: 19 additions & 0 deletions Week2/exercise03.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'use strict'

/*

Exercise 3: The recipe card

Ever wondered how to make a certain meal? Let's create a recipe list with JavaScript!

Declare a variable that holds an empty object literal (your meal recipe).
Give the object 3 properties: a title (string), a servings (number) and an ingredients (array of strings) property.
Log each property out separately, using a loop (for, while or do/while)
Expected result:

Meal name: Omelette
Serves: 2
Ingredients: 4 eggs, 2 strips of bacon, 1 tsp salt/pepper

*/

18 changes: 18 additions & 0 deletions Week2/exercise04.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict'

/*

Exercise 4: The reading list

Keep track of which books you read and which books you want to read!

Follow the steps:

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).
Loop through the array of books.
For each book, log the book title and book author like so: "The Hobbit by J.R.R. Tolkien".
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
If you haven't read it log a string like You still need to read "The Lord of the Rings"

*/

24 changes: 24 additions & 0 deletions Week2/exercise05.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
'use strict'

/*

Exercise 5: Who wants a drink?

You're at a party and you feel thirsty! However, you've got 5 friends who are also in need of a drink. Let's go get them a drink.

Declare a variable that holds an empty array, called drinkTray.
There are 3 different types of drinks:

const drinkTypes = ['cola', 'lemonade', 'water'];
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.
// Expected result:
const drinkTray = ['cola', 'cola', 'lemonade', 'lemonade', 'water'];

// 'Hey guys, I brought a cola, cola, lemonade, lemonade, water!'
If there are already two instances of a drinkType then start with the next drink in the array.
Your drinkTray should contain 2 cola, 2 lemonade and 1 water.
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!")
Test out your code using node in the command line!

*/

34 changes: 34 additions & 0 deletions Week2/project/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
'use strict'

/*

4. PROJECT: Grade calculator
Every week ends with a project you have to build on your own. Instead of getting clear-cut instructions, you'll get a list of criteria that your project needs to measure up to.

In this project you'll write a function that calculates grades, based on the American grading system! Let's say a student did a test and they got a 60 out of 100, this function will:

convert the score into a percentage
calculate what grade corresponds with that percentage, and
shows in the command line the result: the grade and the percentage
In this example this is what we would expect the function to return in the command line:

You got a D (60%)!
When writing the function, make use of the following grade scores:

Grade A (90% - 100%)
Grade B (80% - 89%)
Grade C (70% - 79%)
Grade D (60% - 69%)
Grade E (50% - 59%)
Grade F (0% - 49%)
These are the requirements your project needs to fulfill:

Make a JavaScript file with a name that describes its contents
Use either a switch or if/else statement
Write at least 2 comments that explain to others what a line of code is meant to do
Make the return value of the function a template string, so you can insert variables!
Use node from the command line to test if your code works as expected
Good luck!

*/

21 changes: 21 additions & 0 deletions Week3/exercise01.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict'

/*

Exercise 1: You are amazing, Noer!

There is no better way to start your day then with a compliment!

Write a function named giveCompliment
It takes 1 argument: your name
Inside the function define a variable that holds an array, compliments, with 10 strings. Each string should be a compliment, like "great", "awesome"
Write code that randomly selects a compliment
Return a string: "You are [COMPLIMENT], [YOUR_NAME]!
Call the function three times, giving each function call the same argument: your name.
// Expected output
giveCompliment('Noer'); // Returns "You are amazing, Noer!"
giveCompliment('Noer'); // Returns "You are great, Noer!"
giveCompliment('Noer'); // Returns "You are supersmart, Noer!"

*/

20 changes: 20 additions & 0 deletions Week3/exercise02.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict'

/*

Exercise 2: Dog years

You know how old your dog is in human years, but what about dog years? Let's calculate it!

Write a function named calculateDogAge.
It takes 1 argument: your (fictional) puppy's age (number).
Calculate your dog's age based on the conversion rate of 1 human year to 7 dog years.
Return a string: "Your doggie is [CALCULATED_VALUE] years old in dog years!"
Call the function three times with different sets of values.
// Expected output
calculateDogAge(1); // Returns "Your doggie is 7 years old in dog years!"
calculateDogAge(2); // Returns "Your doggie is 14 years old in dog years!"
calculateDogAge(3); // Returns "Your doggie is 21 years old in dog years!"

*/

Loading