Skip to content

Instantly share code, notes, and snippets.

View appoll's full-sized avatar

Paul Anton appoll

  • Hamburg, Germany
View GitHub Profile
@appoll
appoll / e1.js
Created November 30, 2022 18:56
// // 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);
@appoll
appoll / e0.js
Created November 30, 2022 17:40
// 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("...");
// }
@appoll
appoll / e1.js
Created November 28, 2022 19:31
// 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 = {
@appoll
appoll / e0.js
Created November 28, 2022 18:47
// 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,
@appoll
appoll / e2.js
Created November 25, 2022 18:59
// 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
@appoll
appoll / e1.js
Created November 25, 2022 18:25
// 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];
@appoll
appoll / e0.js
Created November 25, 2022 18:20
// 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:...");
}
@appoll
appoll / e0.js
Created November 23, 2022 18:02
// 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
@appoll
appoll / e1.js
Created November 21, 2022 19:33
// 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++){
@appoll
appoll / e0.js
Created November 21, 2022 18:38
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){