Skip to content
This repository was archived by the owner on Oct 1, 2025. It is now read-only.

Commit 4febe1b

Browse files
committed
feat: Completed Work in Fix Some Bad Code First Section
1 parent e7ab098 commit 4febe1b

File tree

5 files changed

+426
-0
lines changed

5 files changed

+426
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# ignore ALL files in ANY directory named node_modules
2+
node_modules/

09-modern-js/clean.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
const budget = [
2+
{ value: 250, description: 'Sold old TV 📺', user: 'jonas' },
3+
{ value: -45, description: 'Groceries 🥑', user: 'jonas' },
4+
{ value: 3500, description: 'Monthly salary 👩‍💻', user: 'jonas' },
5+
{ value: 300, description: 'Freelancing 👩‍💻', user: 'jonas' },
6+
{ value: -1100, description: 'New iPhone 📱', user: 'jonas' },
7+
{ value: -20, description: 'Candy 🍭', user: 'matilda' },
8+
{ value: -125, description: 'Toys 🚂', user: 'matilda' },
9+
{ value: -1800, description: 'New Laptop 💻', user: 'jonas' },
10+
];
11+
12+
const spendingLimits = {
13+
jonas: 1500,
14+
matilda: 100,
15+
};
16+
17+
const getLimit = function (user)
18+
{
19+
//return return = spendingLimits[user] ? spendingLimits[user] : 0;
20+
return spendingLimits?.[user] ?? 0;
21+
};
22+
23+
const addExpense = function (value, description, user = 'jonas')
24+
{
25+
user = user.toLowerCase();
26+
27+
if (value > getLimit(user)) return;
28+
29+
budget.push({ value: -value, description, user });
30+
};
31+
addExpense(10, 'Pizza 🍕');
32+
addExpense(100, 'Going to movies 🍿', 'Matilda');
33+
addExpense(200, 'Stuff', 'Jay');
34+
console.log(budget);
35+
36+
const check = function ()
37+
{
38+
budget.forEach(entry =>
39+
{
40+
if (entry.value >= -getLimit(entry.user)) return;
41+
42+
entry.flag = 'limit';
43+
});
44+
};
45+
check();
46+
47+
console.log(budget);
48+
49+
const logBigExpenses = function (bigLimit)
50+
{
51+
const output = '';
52+
budget.forEach(entry =>
53+
{
54+
output += (entry.value <= -bigLimit) ? `${ entry.description.slice(-2) } / ` : ''; // Emojis are 2 chars
55+
});
56+
output = output.slice(0, -2); // Remove last '/ '
57+
console.log(output);
58+
};

09-modern-js/index.html

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
8+
<script defer src="clean.js"></script>
9+
<title>Modern JavaScript Development: Modules and Tooling</title>
10+
<style>
11+
body {
12+
height: 100vh;
13+
display: flex;
14+
align-items: center;
15+
background: linear-gradient(to top left, #28b487, #7dd56f);
16+
}
17+
18+
h1 {
19+
font-family: sans-serif;
20+
font-size: 50px;
21+
line-height: 1.3;
22+
width: 100%;
23+
padding: 30px;
24+
text-align: center;
25+
color: white;
26+
}
27+
</style>
28+
</head>
29+
30+
<body>
31+
<h1>Modern JavaScript Development: Modules and Tooling</h1>
32+
</body>
33+
34+
</html>

09-modern-js/script.js

Whitespace-only changes.

0 commit comments

Comments
 (0)