Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
235 changes: 232 additions & 3 deletions challenges.js
Original file line number Diff line number Diff line change
@@ -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`
Expand All @@ -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)}.`);



Expand All @@ -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);



Expand All @@ -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 🚀🚀🚀🚀
Expand All @@ -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 🏈🏈🏈🏈
Expand Down Expand Up @@ -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.
*/
*/

// 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);
}




























































































1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
<body>
<h1>Check the console log for changes</h1>

<script src="challenges.js"></script>
</body>
</html>