Skip to content
Snippets Groups Projects
Commit f72fcc43 authored by Subliminal Guy's avatar Subliminal Guy
Browse files

Small Changes

parent 25e29d7f
No related branches found
No related tags found
No related merge requests found
function calculateSum(numbers) { function calculateSum(numbers) {
let sum = 0; let sum = 0;
for (let i = 0; i <= numbers.length; i++) { for (let i = 0; i <= numbers.length; i++) {
sum += numbers[i]; sum += numbers[i];
}
return sum;
} }
return sum;
}
const myNumbers = [10, 20, 30, 40, 50]; const myNumbers = [10, 20, 30, 40, 50];
const result = calculateSum(myNumbers); const result = calculateSum(myNumbers);
console.log("The sum is:", result); console.log("The sum is:", result);
\ No newline at end of file \ No newline at end of file
function makeUpperCase(name) { function makeUpperCase(name) {
if (typeof name !== "string") { if (typeof name !== "string") {
throw new Error("Name must be a string"); throw new Error("Name must be a string");
} }
else { else {
return name.toUpperCase(); return name.toUpperCase();
} }
} }
let result
try { try {
let result = makeUpperCase(1223); result = makeUpperCase(1223);
} }
catch (error) { catch (error) {
console.log("Da gab es einen Fehler: ", error.message); console.log("Da gab es einen Fehler: ", error.message);
} }
console.log(result)
function brewPotion(ingredient1, ingredient2) { function brewPotion(ingredient1, ingredient2) {
// Ensure both ingredients are provided // Ensure both ingredients are provided
if (!ingredient1 || !ingredient2) { if (!ingredient1 || !ingredient2) {
throw new Error("Both ingredients are required."); throw new Error("Both ingredients are required.");
} }
// Combine the ingredients with a dash and capitalize them correctly // Combine the ingredients with a dash and capitalize them correctly
return ingredient1 + ingredient2 return ingredient1 + ingredient2
} }
console.log(brewPotion("apple")) console.log(brewPotion("apple"))
\ No newline at end of file
function greetUser(name) { function greetUser(name) {
let greeting = "Hello, " + name + "!"; let greeting = "Hello, " + name + "!";
console.log(greeting); console.log(greeting);
} }
const userName = "Alice"; const userName = "Alice";
greetUser(username); greetUser(username);
\ No newline at end of file \ No newline at end of file
const questions = [ const questions = [
{ {
category: "Geography", category: "Geography",
question: "What is the capital of France?", question: "What is the capital of France?",
choices: ["London", "Paris", "Berlin", "Rome"], choices: ["London", "Paris", "Berlin", "Rome"],
answer: "Paris" answer: "Paris"
}, },
{ {
category: "Movies", category: "Movies",
question: "What is the name of the main character in The Matrix?", question: "What is the name of the main character in The Matrix?",
choices: ["Neo", "Trinity", "Morpheus", "Cypher"], choices: ["Neo", "Trinity", "Morpheus", "Cypher"],
answer: "Neo" answer: "Neo"
}, },
{ {
category: "History", category: "History",
question: "Who was the first president of the United States?", question: "Who was the first president of the United States?",
choices: ["John Adams", "Thomas Jefferson", "George Washington", "Abraham Lincoln"], choices: ["John Adams", "Thomas Jefferson",
answer: "George Washington" "George Washington", "Abraham Lincoln"],
}, answer: "George Washington"
{ },
category: "Sports", {
question: "Which team won the World Cup in 2018?", category: "Sports",
choices: ["France", "Brazil", "Germany", "Italy"], question: "Which team won the World Cup in 2018?",
answer: "France" choices: ["France", "Brazil", "Germany", "Italy"],
} , answer: "France"
{ } ,
category: "Science", {
question: "What is the chemical symbol for gold?", category: "Science",
choices: ["Au", "Ag", "Pt", "Cu"], question: "What is the chemical symbol for gold?",
answer: "Au" choices: ["Au", "Ag", "Pt", "Cu"],
} answer: "Au"
}
] ]
export default questions export default questions
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment