hinzugefügt clean coding App
This commit is contained in:
parent
2a4fa520b6
commit
5f8b6f777c
64
javascript/Javascript Expert/chapter17/starter/clean.js
Normal file
64
javascript/Javascript Expert/chapter17/starter/clean.js
Normal file
@ -0,0 +1,64 @@
|
||||
var budget = [
|
||||
{ value: 250, description: "Sold old TV 📺", user: "david" },
|
||||
{ value: -45, description: "Groceries 🥑", user: "david" },
|
||||
{ value: 3500, description: "Monthly salary 👩💻", user: "david" },
|
||||
{ value: 300, description: "Freelancing 👩💻", user: "david" },
|
||||
{ value: -1100, description: "New iPhone 📱", user: "david" },
|
||||
{ value: -20, description: "Candy 🍭", user: "joanne" },
|
||||
{ value: -125, description: "Toys 🚂", user: "joanne" },
|
||||
{ value: -1800, description: "New Laptop 💻", user: "david" },
|
||||
];
|
||||
|
||||
var limits = {
|
||||
david: 1500,
|
||||
joanne: 100,
|
||||
};
|
||||
|
||||
var add = function (value, description, user) {
|
||||
if (!user) user = "david";
|
||||
user = user.toLowerCase();
|
||||
|
||||
var lim;
|
||||
if (limits[user]) {
|
||||
lim = limits[user];
|
||||
} else {
|
||||
lim = 0;
|
||||
}
|
||||
|
||||
if (value <= lim) {
|
||||
budget.push({ value: -value, description: description, user: user });
|
||||
}
|
||||
};
|
||||
add(10, "Pizza 🍕");
|
||||
add(100, "Going to movies 🍿", "Matilda");
|
||||
add(200, "Stuff", "Jay");
|
||||
console.log(budget);
|
||||
|
||||
var check = function () {
|
||||
for (var el of budget) {
|
||||
var lim;
|
||||
if (limits[el.user]) {
|
||||
lim = limits[el.user];
|
||||
} else {
|
||||
lim = 0;
|
||||
}
|
||||
|
||||
if (el.value < -lim) {
|
||||
el.flag = "limit";
|
||||
}
|
||||
}
|
||||
};
|
||||
check();
|
||||
|
||||
console.log(budget);
|
||||
|
||||
var bigExpenses = function (limit) {
|
||||
var output = "";
|
||||
for (var el of budget) {
|
||||
if (el.value <= -limit) {
|
||||
output += el.description.slice(-2) + " / "; // Emojis are 2 chars
|
||||
}
|
||||
}
|
||||
output = output.slice(0, -2); // Remove last '/ '
|
||||
console.log(output);
|
||||
};
|
||||
31
javascript/Javascript Expert/chapter17/starter/index.html
Normal file
31
javascript/Javascript Expert/chapter17/starter/index.html
Normal file
@ -0,0 +1,31 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
|
||||
<!-- <script defer src="script.js"></script> -->
|
||||
<script defer src="clean.js"></script>
|
||||
<title>Modern JavaScript Development: Modules and Tooling</title>
|
||||
<style>
|
||||
body {
|
||||
height: 100vh;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
background: linear-gradient(to top left, #28b487, #7dd56f);
|
||||
}
|
||||
h1 {
|
||||
font-family: sans-serif;
|
||||
font-size: 50px;
|
||||
line-height: 1.3;
|
||||
width: 100%;
|
||||
padding: 30px;
|
||||
text-align: center;
|
||||
color: white;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Modern JavaScript Development: Modules and Tooling</h1>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
x
Reference in New Issue
Block a user