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
129 changes: 117 additions & 12 deletions challenges.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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.
Expand All @@ -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 🚀🚀🚀🚀
Expand All @@ -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
Expand All @@ -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.
*/
*/




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

</body>
</html>