Here you find the readings you have to complete before the third lecture.
Deadline Monday
Provide feedback to step 1 and step 3 of the homework of last week to one of your fellow students. You will be assigned to one of the assignments by the class lead of this week.
- Have a look at The Secret Life of JavaScript Primitives
- Go through the review of last week
- Go through the review of this week
- If you haven't done already, watch: What is programming Just watch the 2 min video, you do not have to do the entire JavaScript course (It could be useful later on though).
- Please watch the following parts of the course, Programming Foundations Fundamentals on Lynda.com (if you don't have access to Lynda yet ask Gijs):
4. Writing Conditional Code
5. Modular Code
6. Iteration: Writing Loops
7. More About Strings
8. Collections
11. When Things Go Wrong
Go and try out this cool game: http://hyf-robot.herokuapp.com/index.html, there are different levels, see how far you can get!
Deadline Thursday
For all the following exercises create a new .js file. Try to find a proper name for each file or make a small comment about what it does inside for future reference
IMPORTANT NOTE
In each assignment write at least two console.log statements to verify if your code works correctly. In other words proof that you code works as expected. If you need inspiration look at the steps defined in the assignments from last week.
-
Create a function that takes 3 arguments and returns the sum of the three arguments.
-
Create a function named
colorCarthat receives a color, and prints out, "a red car" for example. -
Create an object and a function that takes the object as a parameter and prints out all of its names and values.
-
Create a function named
vehicleTypethat receives a color, and a code, 1 for car, 2 for motorbike. And prints "a blue motorbike" for example when called asvehicleType("blue", 2) -
Can you write the following without the
ifstatement, but with just as a single line withconsole.log(...);?if (3 === 3) { console.log("true") } else { console.log("false") }
-
Create a function called
vehicle, like before, but takes another parameter called age, so thatvehicle("blue", 1, 5)prints "a blue used car" -
Make a list of vehicles, you can add
"motorbike","caravan","bike", or more. -
How do you get the third element from that list?
-
Change the function
vehicleto use the list of question 7. So thatvehicle("green", 3, 1)prints "a green new caravan". -
Use the list of vehicles to write an advertisement. So that it prints something like:
"Amazing Joe's Garage, we service cars, motorbikes, caravans and bikes.". (Hint: use aforloop.) -
What if you add one more vehicle to the list, can you have that added to the advertisement without changing the code for question 10?
-
Create an empty object.
-
Create an object that contains the teachers that you have had so far for the different modules.
-
Add a property to the object you just created that contains the languages that they have taught you.
-
We saw that we can pass functions as arguments to other functions. Your task is to write a function that takes another function as an argument and runs it.
function foo(func) { // What to do here? } function bar() { console.log('Hello, I am bar!'); } foo(bar);
-
Write some code to test two arrays for equality using
==and===. Test the following:let x = [1,2,3]; let y = [1,2,3]; let z = y;
What do you think will happen with
x == y,x === yandz == yandz == x? Prove it!Don't cheat! Seriously - try it first.
Check out this Fiddle. You need to open your browser’s Developer Tools to see the console output. Press the Run button in the upper right corner to run the code.
More insights from this Stack Overflow question.
-
Take a look at the following code:
let o1 = { foo: 'bar' }; let o2 = { foo: 'bar' }; let o3 = o2;
Show that changing
o2changeso3(or not) and changingo1changeso3(or not).Does the order that you assign (
o3 = o2oro2 = o3) matter? -
What does the following code return? (And why?)
let bar = 42; typeof typeof bar;
‘Coerce' means to try to change - so coercing
var x = '6'to number means trying to change the type to number temporarily.
Deadline Saturday
Go back to FreeCodeCamp, start where you left of and finish the rest of the Basic JavaScript challenges.
Please make sure you REALLY understand the exercises below:
- https://www.freecodecamp.com/challenges/multiply-two-decimals-with-javascript
- https://www.freecodecamp.com/challenges/store-multiple-values-in-one-variable-using-javascript-arrays
- https://www.freecodecamp.com/challenges/build-javascript-objects
- https://www.freecodecamp.com/challenges/add-new-properties-to-a-javascript-object
- https://www.freecodecamp.com/challenges/delete-properties-from-a-javascript-object
How to hand in your homework:
• Upload your homework in your "hyf-javascript1" Github repository. Make sure to create a new folder "week2" first.
• Upload your homework files inside the week2 folder and write a description for this “commit”.
• Your hyf-javascript1/week2 should now contain all your homework files.
• Place the link to your repository folder in Trello.
⭐ Additional resources and review: here (work in progress):star: