From 3c80a1597e3c0a3116c639a8e8f66fcefc206a50 Mon Sep 17 00:00:00 2001 From: Muna Mohamud Date: Fri, 7 Nov 2025 20:42:20 -0600 Subject: [PATCH] finished assignment --- challenges.js | 129 +++++++++++++++++++++++++++++++++++++++++++++----- index.html | 1 + 2 files changed, 118 insertions(+), 12 deletions(-) diff --git a/challenges.js b/challenges.js index 9813c94..df31cc3 100644 --- a/challenges.js +++ b/challenges.js @@ -18,6 +18,15 @@ Output: "The late fee is $2.50." // ✍️ ✍️ ✍️ ✍️ Write the function here ✍️ ✍️ ✍️ ✍️ +function calculateLateFee(){ + const user =prompt("Enter late days") + const lateFee=0.250 + const total=user*lateFee + console.log(`The late fee is $${total}`) + +} +calculateLateFee(); + // Extra Task: @@ -45,7 +54,26 @@ Output: "Red: You are passionate and bold." // ✍️ ✍️ ✍️ ✍️ Write the function here ✍️ ✍️ ✍️ ✍️ - +function findColorMeaning(){ + const UserInput=prompt("Whats Your favourite color?") + if(UserInput=="Blue"){ + console.log("You love calm and peace.") + } + else if(UserInput=="Red"){ + console.log("You are passionate and bold.") + } + else if(UserInput=="Green"){ + console.log("You are connected to nature.") + } + else if(UserInput=="Yellow"){ + console.log("You radiate happiness and energy.") + } + else{ + console.log("That's a unique choice!") + } +} + +findColorMeaning(); // Extra Task: // - Rewrite the function using an arrow function. @@ -68,11 +96,19 @@ Output: "Case #12345: John Doe's case is now logged." // ✍️ ✍️ ✍️ ✍️ Write the function here ✍️ ✍️ ✍️ ✍️ - +const logCase =function( number,name){ + console.log(`Case #${number}: ${name}'s case is now logged`) +} +logCase(12345,"Ahmed") // Extra Task: // - Rewrite the function as an arrow function. +const logCase =(number,name) =>{ + console.log(`Case #${number}: ${name}'s case is now logged`) +} +logCase(12345,"Ali") + /* Task 4 : Attendance Tracker 🚀🚀🚀🚀 @@ -90,39 +126,104 @@ If the student is absent, log: Example: Input: markAttendance("Amina", true) Output: "Amina is present." -*/ +*/ // ✍️ ✍️ ✍️ ✍️ Write the function here ✍️ ✍️ ✍️ ✍️ +function markAttendance(studentName, isPresent){ + if (isPresent === true){ + console.log(`${studentName} is present`) + } + else{ + console.log(`${studentName} is absent`) + } + +} +markAttendance("Deka",true) +markAttendance("Muna",false) + + + // Extra Task: // - Convert the function into a function expression. -/* -STRETCH TASK: Student Grade Report Generator 🏈🏈🏈🏈 -You are a teacher, and you want to automate the creation of detailed grade reports for your class. Write a program that includes the following steps: +//STRETCH TASK: Student Grade Report Generator 🏈🏈🏈🏈 + +//You are a teacher, and you want to automate the creation of detailed grade reports for your class. Write a program that includes the following steps: + -1. Write a function called `calculateAverage` that takes three test scores (numbers) as parameters and returns the average of those scores. +//1. Write a function called `calculateAverage` that takes three test scores (numbers) as parameters and returns the average of those scores. + +function calculateAverage(n1, n2, n3) { + const add = (n1 + n2 + n3) / 3 + return add +} -2. Write another function called `determineGrade` that takes the average score as a parameter and returns the letter grade based on the following rules: +console.log(calculateAverage(77, 50, 60)) + + +/*2. Write another function called `determineGrade` that takes the average score as a parameter and returns the letter grade based on the following rules: - "A" for average scores of 90 and above - "B" for scores between 80 and 89 - "C" for scores between 70 and 79 - "F" for scores below 70 - -3. Write a third function called `generateReport` that: + */ + + function determineGrade(calculateAverage){ + if(calculateAverage>=90){ + return "A" + } + else if(calculateAverage>=80 && calculateAverage<=89){ + return "B" + + } + else if(calculateAverage>=70 && calculateAverage<=79){ + return "C" + } + else{ + return "F" + } + } + console.log(determineGrade(69)) + + +/*3. Write a third function called `generateReport` that: - Takes a student's name and three test scores as parameters. - Uses `calculateAverage` to calculate the average score. - Uses `determineGrade` to find the letter grade. - Returns a full report string in this format: "[StudentName] - Average Score: [average], Grade: [letterGrade]" + */ + + function generateReport(sName,n1,n2,n3){ + + const average=calculateAverage(n1,n2,n3) + const grade=determineGrade(average) + return `${sName} -Average Score:${average}, Grade: ${grade}` + + } + console.log(generateReport("Muna",90,20,90)) + +//4. Finally, use the `prompt` function to input the student’s name and three test scores, and display the generated report using `console.log`. -4. Finally, use the `prompt` function to input the student’s name and three test scores, and display the generated report using `console.log`. +function displayGeneateReport(){ + const stdName=prompt("Input Student name:") + const score1=Number(prompt("Enter score1")) + const score2=Number(prompt("Enter score2")) + const score3=Number(prompt("Enter score3")) + const average=calculateAverage(score1,score2,score3) + const grade=determineGrade(average) + return `${stdName} -Average Score:${average}, Grade: ${grade}` + +} +console.log(displayGeneateReport()) +/* Example: User Input: Name: Amina @@ -134,4 +235,8 @@ 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 +*/ + + + + diff --git a/index.html b/index.html index a56d8b1..92ae83b 100644 --- a/index.html +++ b/index.html @@ -5,6 +5,7 @@

Check the console log for changes

+