From 048f12ee78c71a1a0d9a1a1ad892a5affae61b26 Mon Sep 17 00:00:00 2001 From: abdiwelimohamud Date: Sun, 1 Mar 2026 14:17:01 +0200 Subject: [PATCH] finished --- challenges.js | 235 +++++++++++++++++++++++++++++++++++++++++++++++++- index.html | 1 + 2 files changed, 233 insertions(+), 3 deletions(-) diff --git a/challenges.js b/challenges.js index 9813c94..a64017b 100644 --- a/challenges.js +++ b/challenges.js @@ -1,5 +1,6 @@ /* Task 1: Library Late Fee Calculator 🚀🚀🚀🚀 +co You are working at a library and need to calculate late fees for overdue books. Write a function called `calculateLateFee` @@ -16,12 +17,35 @@ User Input: 10 Output: "The late fee is $2.50." */ -// ✍️ ✍️ ✍️ ✍️ Write the function here ✍️ ✍️ ✍️ ✍️ +// ✍️ ✍️ ✍️ ✍️ Write the function here ✍️ ✍️ ✍️ ✍️ + +// function calculateLateFee(daysOverdue) { +// const feePerDay = 0.25; +// return daysOverdue * feePerDay; +// } +// let userInput = prompt("Enter the number of overdue days:"); +// let days = parseInt(userInput); +// let totalFee = calculateLateFee(days); +// console.log(`The late fee is $${totalFee.toFixed(2)}.`); // Extra Task: // - Convert the function into a function expression. +// const calculateLateFee = function(daysOverdue) { +// const feePerDay = 0.25; +// return daysOverdue * feePerDay; +// }; + +// // Prompt user for input +// let userInput = prompt("Enter the number of overdue days:"); +// let days = parseInt(userInput); + +// // Calculate fee +// let totalFee = calculateLateFee(days); + +// // Log result +// console.log(`The late fee is $${totalFee.toFixed(2)}.`); @@ -44,11 +68,59 @@ Output: "Red: You are passionate and bold." */ // ✍️ ✍️ ✍️ ✍️ Write the function here ✍️ ✍️ ✍️ ✍️ +// function findColorMeaning(color) { +// color = color.toLowerCase(); + +// if (color === "blue") { +// console.log("Blue: You love calm and peace."); +// } +// else if (color === "red") { +// console.log("Red: You are passionate and bold."); +// } +// else if (color === "green") { +// console.log("Green: You are connected to nature."); +// } +// else if (color === "yellow") { +// console.log("Yellow: You radiate happiness and energy."); +// } +// else { +// console.log("That's a unique choice!"); +// } +// } +// let userColor = prompt("Enter your favorite color:"); +// findColorMeaning(userColor); + // Extra Task: // - Rewrite the function using an arrow function. +// const findColorMeaning = (color) => { +// // Convert input to lowercase +// color = color.toLowerCase(); + +// if (color === "blue") { +// console.log("Blue: You love calm and peace."); +// } +// else if (color === "red") { +// console.log("Red: You are passionate and bold."); +// } +// else if (color === "green") { +// console.log("Green: You are connected to nature."); +// } +// else if (color === "yellow") { +// console.log("Yellow: You radiate happiness and energy."); +// } +// else { +// console.log("That's a unique choice!"); +// } +// }; + +// // Prompt user for input +// let userColor = prompt("Enter your favorite color:"); + +// // Call the arrow function +// findColorMeaning(userColor); @@ -67,12 +139,22 @@ Output: "Case #12345: John Doe's case is now logged." */ // ✍️ ✍️ ✍️ ✍️ Write the function here ✍️ ✍️ ✍️ ✍️ +// Task 3 : Lawyer's Case Log 🚀 +// function logCase(clientName, caseNumber) { +// console.log(`Case #${caseNumber}: ${clientName}'s case is now logged.`); +// } +// logCase("Abdiweli mohamud", 12345); // Extra Task: // - Rewrite the function as an arrow function. +// const logCase = (clientName, caseNumber) => { +// console.log(`Case #${caseNumber}: ${clientName}'s case is now logged.`); +// }; +// // Example call +// logCase("Abdiweli mohamud", 12345); /* Task 4 : Attendance Tracker 🚀🚀🚀🚀 @@ -94,12 +176,28 @@ Output: "Amina is present." // ✍️ ✍️ ✍️ ✍️ Write the function here ✍️ ✍️ ✍️ ✍️ +// function markAttendance(studentName, isPresent) { +// if (isPresent) { +// console.log(`${studentName} is present.`); +// } else { +// console.log(`${studentName} is absent.`); +// } +// } +// markAttendance("Amina", true); + // Extra Task: // - Convert the function into a function expression. - +// const markAttendance = function(studentName, isPresent) { +// if (isPresent) { +// console.log(`${studentName} is present.`); +// } else { +// console.log(`${studentName} is absent.`); +// } +// }; +// markAttendance("Abdiweli", true); /* STRETCH TASK: Student Grade Report Generator 🏈🏈🏈🏈 @@ -134,4 +232,135 @@ Output: Extra Credit: - Extend the program to accept multiple students' names and scores and generate a report for each student using a loop. - Use an arrow function for at least one of the functions. -*/ \ No newline at end of file +*/ + +// Function to calculate the average (rounded to 2 decimal places) +function calculateAverage(score1, score2, score3) { + let total = score1 + score2 + score3; + return Number((total / 3).toFixed(2)); +} + +// Arrow function to determine the letter grade +const determineGrade = (average) => { + if (average >= 90) return "A"; + else if (average >= 80) return "B"; + else if (average >= 70) return "C"; + else return "F"; +}; + +// Function to generate report +function generateReport(studentName, score1, score2, score3) { + let average = calculateAverage(score1, score2, score3); + let letterGrade = determineGrade(average); + return `${studentName} - Average Score: ${average}, Grade: ${letterGrade}`; +} + +// Ask how many students to enter +let numberOfStudents = Number(prompt("Enter number of students:")); + +// Loop through each student +for (let i = 1; i <= numberOfStudents; i++) { + + console.log(`\nEntering details for student ${i}`); + + let name = prompt("Enter student's name:"); + let score1 = Number(prompt("Enter first test score:")); + let score2 = Number(prompt("Enter second test score:")); + let score3 = Number(prompt("Enter third test score:")); + + // Generate and display report + let report = generateReport(name, score1, score2, score3); + console.log(report); +} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/index.html b/index.html index a56d8b1..c62a2a9 100644 --- a/index.html +++ b/index.html @@ -6,5 +6,6 @@

Check the console log for changes

+