-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsharing-task.js
More file actions
151 lines (121 loc) · 4.44 KB
/
Copy pathsharing-task.js
File metadata and controls
151 lines (121 loc) · 4.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*
===========================================
🤝 Collaborative Coding Challenge: Event Helpers
===========================================
🎯 Objective:
Students will work in small teams to collaboratively design and implement
reusable functions that solve specific tasks. This activity encourages:
- Teamwork
- Critical thinking
- Knowledge sharing
*/
// ============================================
// 🎉 Scenario:
// Your bootcamp is organizing an event to showcase projects.
// Your team will write reusable JavaScript functions to help manage the event.
// Each function must:
// - Use parameters
// - Use return statements
// - Follow the single responsibility principle
// ============================================
// ============================================
// 🧩 Task 1: Generate Attendee Badge
// ============================================
// Create a function that:
// - Takes a name and a role (e.g., "Alice", "speaker")
// - Returns a string in the format: "Name: Alice, Role: Speaker"
// Steps:
// 1. Define the function with two parameters.
// 2. Format the output string properly.
// 3. Capitalize the role if needed.
// 4. Return the result.
function createAttendeeBadge(name, role) {
let roleUpper = role[0].toUpperCase();
roleUpper += role.slice(1);
let output = "Name: " + name + ", Role: " + roleUpper;
//Role.toLowerCase.Reverse()
return output;
}
//testing
let attendee = createAttendeeBadge("Mary","cook");
console.log(attendee);
// ============================================
// 🧩 Task 2: Calculate Event Cost
// ============================================
// Create a function that:
// - Takes number of attendees and cost per attendee.
// - Applies a 10% discount if attendees exceed 100.
// - Returns the total cost.
// Steps:
// 1. Multiply attendees by cost.
// 2. Check if attendee count is over 100.
// 3. If so, apply a 10% discount.
// 4. Return the final total.
function calculateEventCost(attendees, costPerAttendee) {
let totalCost = attendees * costPerAttendee;
if (attendees > 100) {
totalCost = totalCost * 0.9;
//totalCost *= 0.9;
}
return totalCost;
}
//testing
let concertgoers = 50;
let sportsGameAttendees = 120;
let concertCost = 10.50;
let sportsGameCost = 10;
console.log("Concert cost for " + concertgoers + " attendees at " + concertCost + " per attendee: $" + calculateEventCost(concertgoers, concertCost));
console.log("Sports Game cost for " + sportsGameAttendees + " atendees at " + sportsGameCost + " per attendee: $" + calculateEventCost(sportsGameAttendees,sportsGameCost));
// ============================================
// 🧩 Task 3: Validate Email
// ============================================
// Create a function that:
// - Takes an email string as input.
// - Returns true if the email contains both "@" and "." characters.
// - Returns false otherwise.
// Steps:
// 1. Check if the string includes both "@" and ".".
// 2. Return true or false accordingly.
function validateEmail(emailAddress) {
if (emailAddress.includes("@") && emailAddress.includes(".")) {
return true;
} else {
return false;
}
/* "The Hard Way", or how Bradley was gonna to do it.
let isValid = false;
for (let i = 0; i < emailAddress && isValid == false; i++){
if // emailAddress[0] is equal to "@",{
hasAmpersand = true;
}
if // emailAddress[0] is equal to ".", {
hasPeriod = true
}
if (hasAmpersand && hasPeriod){
isValid = true;
}
}
*/
}
//testing
console.log(validateEmail("@gmail.com"));
console.log(validateEmail("Dummystring"));
// ============================================
// 🧠 Collaborative Steps
// ============================================
// 📌 Design Phase:
// - Brainstorm function requirements: What inputs and outputs are needed?
// - Assign roles within your team:
// ▸ Pseudocode Writer
// ▸ Initial Coder
// ▸ Testers / Debuggers
// 🛠️ Implementation Phase:
// - Write and refine your three functions as a team
// - Use return statements and ensure reusability
// 🧪 Testing Phase:
// - Each member writes test cases for each function
// - Use console.log() to test different inputs and edge cases
// 🎤 Presentation Phase:
// - Share your functions with the class
// - Explain how your team approached the design and testing process
// ✅ Bonus: Can you extend any of the functions to be more flexible or reusable?