This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// E1. Print all even numbers between 10 and 20 (including 10 and 20). An even number is a number | |
// x for which the following is true: x % 2 === 0 | |
for (i=0; i<=10; i+=1){ | |
console.log(i); | |
console.log("I am at i = " + i); | |
} | |
// E2. Iterate from 0 to 50; Print "##" for even numbers and "!!" for odd numbers; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Uncomment the code between /* and */; | |
// Run the code; | |
// See what happens; | |
// Does it make sense? | |
// AND operator: && | |
// 3.1 | |
userName = "Siri" | |
if (3 > 1 && userName === "Siri"){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Uncomment the code between /* and */; | |
// Run the code; | |
// See what happens; | |
// Does it make sense? | |
// 1.0 | |
age = 18; | |
if (age == 18) { | |
console.log("1.0 Yes!"); | |
} else { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// E6 | |
// division / | |
// 5 Friends are travelling to Berlin. The total cost of gas is 189 EUR. | |
//How much does each of them have to pay the driver? | |
// console.log("Cost per traveller is: " + costPerPerson); | |
// E7 | |
// E7: Input: the year 1990. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// E3. | |
// a. Create a variable and give it the value of your home city; print it; | |
// b. Create a second variable for the city in which you were born; print it; | |
// c. Create a 3rd variable and store the distance between the 2 cities; | |
// d. Print the following on one line: | |
// I was born in .... I now live in ..... The distance between ... and .... is ... kilometers |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Exercise 0 - Uncomment and Fix the lines below: | |
// console.log("My message 4); | |
// console.log("My message 4"; | |
// consolelog("My message 4"); | |
// Exercise 1 | |
// Print your three favourite cities, each city on each line. The output should look like this: | |
/* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// objects can have arrays as properties | |
// E1. Let's find out how many bikes the user has | |
// 1.1 write one line of code to print how many bikes the user has | |
// 1.2 write a function that takes an user as parameter and returns the number of bikes the user has | |
let person = { | |
firstName: "Paul", | |
lastName: "Anton", | |
age: 28, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// E4. | |
// Write a function that takes two parameters: an array and a Number; | |
// The function returns the index of | |
// the element's first occurence in the array; | |
function findPositionOfNumberInArray(array, number) { | |
// iterate over the array -> for loop | |
// compare the item of each position in the array to the <givenNumber> | |
// -> equality operator === | |
// -> if statement |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// E1. The following function should return the sum of all elements in an array; | |
// The result of the code below should print: | |
// 8 | |
// 4 | |
// Fix the code below to work as expected: | |
let sum = 0; | |
function sumOfArrayValues(array){ | |
for (let i=0; i<array.length; i++) { | |
sum += array[i]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// E0. | |
// Write a function that prints the sum of two numbers. | |
// The 2 numbers should be passed in as parameters | |
// e.g. add(3,5) | |
function addNumbers(number1, number2){ | |
console.log("The sum is:..."); | |
} | |
addNumbers(10, 100); |