Skip to content

Instantly share code, notes, and snippets.

View appoll's full-sized avatar

Paul Anton appoll

  • Hamburg, Germany
View GitHub Profile
ages = [12, 16, 24, 28, 69, 14, 13, 80]
// E0. Copy all ages which are greater than 18 to a second array
largerThan18 = []
for (i=0; i < ages.length; i++){
}
console.log("Input: " + ages);
ages = [12, 16, 24, 98, 64, 24, 98, 64, 24, 98, 64]
// Print all the ages in your array :)
// We use the for loop
for (i = 0; i < ages.length; i = i + 1){
currentAge = ages[i];
console.log("Position is: " + i);
console.log("Value is: " + currentAge);
}
// 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 = 10; i < 21; i++ ) {
}
// 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!");
// 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"){
// We define a variable for the users' age; We want to check if they are over 18, in order to be able to drink beer or not;
// Print the following messages: "You are able to drink beer, since you were born in the year: 1992" OR
// "You are NOT able to drink beer, since you were born in the year: 2016"
if (age > 12){
console.log("YES it is");
} else {
// text variables
customerName = "Florian";
customerEmail = "[email protected]"
// numerical variables
customerAge = 25;
console.log("My name is: " + customerName);
// E1
// 1.1 Write a function that decreases the price of a book to half of its value
// 1.2 Write a function that converts a book's authors' last name to lowercase
// .toLower()
// 1.3 Write a function that converts a book's authors' last name to uppercase
// .toUpper()
let b1 = {
title: "Gone with the wind",
let b1 = {
title: "Gone with the wind",
price: 30,
currency: "EUR"
}
let b2 = {
title: "The godfather",
price: 40,
let book1 = {
pages: 200,
year: 2022,
authors:
[
{
firstName: "Paul",
lastName: "Anton"