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
// // Add the string "passed" to every element in the array below: | |
let students = ["Sebastian", "Oliver", "Samuel", "Hugo", "Lily", "Vasilis"] | |
students.forEach((value, index, array) => { | |
console.log(value); | |
array[index] += " passed"; | |
}) | |
console.log(students); |
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
// Same exercises from lesson 6 e0.js & e1.js | |
// E1. | |
// Write an arrow function that takes as parameters: the userName and the userBirthMonth and prints the following: | |
// "Hello, <userName>. Your birth month is: <birthMonth>" | |
// function helloUser(userName, birthMonth) { | |
console.log("..."); | |
// } |
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
// E5 - same like E3, but books are in an array now | |
// 5.1 Use a for loop to decrease the price of all books in the array to half of their original price | |
// 5.2 Use a for loop to convert all books' authors' last name to lowercase | |
// .toLower() | |
// 5.3 Use a for loop to convert all books' authors' last name to uppercase | |
// .toUpper() | |
// 5.4 Use a for loop to increase the price of all books written in german by 10 percent | |
let b1 = { |
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 void 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:..."); | |
} |
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. Increase all prices larger than 2000 with 10%; | |
prices = [120, 1600, 2400, 2800] | |
for (i=0; i < prices.length; i++){ | |
} | |
console.log("Result: " + prices); | |
// 120, 1600, 2640, 3080 | |
// E1 | |
// Start with 2 hardcoded arrays, e.g. prices1 & prices2 |
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
// E7. | |
// Start with 2 hardcoded arrays, e.g. prices1 & prices2 | |
// Calculate a third array that contains the sum of the elements in the first two arrays. | |
prices1 = [12, 16, 24, 28] | |
prices2 = [1, 1, 1, 1] | |
pricesSum = [] | |
for (i=0; i < prices1.length; 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
ages = [12, 16, 24, 98] | |
// E0. Print all the ages in the array in reverse order; | |
for (let i = 0; i < ages.length; i = i + 1){ | |
console.log(ages[i]); | |
} | |
// E1. Print all positions of all ages greater than 18; | |
for (let i = 0; i < ages.length; i = i + 1){ |
NewerOlder