Skip to content

Commit eac4af5

Browse files
Merge pull request #13 from felipeozalmeida/lint-files
Linted files (now with Prettier)
2 parents 6c479c5 + 5ff88bd commit eac4af5

File tree

10 files changed

+159
-153
lines changed

10 files changed

+159
-153
lines changed

source/scripts/ex1.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
for (let i = 1000; i <= 2000; i++) {
22
if (i % 11 === 5) {
3-
document.write(`${i} % 11 = 5<br>`)
3+
document.write(`${i} % 11 = 5<br>`);
44
}
55
}

source/scripts/ex10.js

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,52 +3,52 @@
33
// https://google.github.io/styleguide/jsguide.html#naming-enum-names
44

55
const PaymentOption = {
6-
CASH: 'cash',
7-
CREDIT: 'credit'
8-
}
6+
CASH: "cash",
7+
CREDIT: "credit"
8+
};
99

10-
const transactions = []
11-
let totalCash = 0
12-
let totalCreditCard = 0
13-
let totalOverall = 0
10+
const transactions = [];
11+
let totalCash = 0;
12+
let totalCreditCard = 0;
13+
let totalOverall = 0;
1414

1515
for (let i = 0; i < 3; i++) {
1616
const transaction = {
1717
id: i,
18-
type: '',
18+
type: "",
1919
value: 0
20-
}
20+
};
2121
const paymentOption = prompt(
2222
'What\'s the transaction type: "cash" or "credit"? (default: cash)'
23-
).toLowerCase()
23+
).toLowerCase();
2424
if (paymentOption === PaymentOption.CREDIT) {
25-
transaction.type = paymentOption
25+
transaction.type = paymentOption;
2626
} else {
27-
transaction.type = PaymentOption.CASH
27+
transaction.type = PaymentOption.CASH;
2828
}
29-
transaction.value = parseFloat(prompt("What's the transaction value?"))
30-
transactions.push(transaction)
29+
transaction.value = parseFloat(prompt("What's the transaction value?"));
30+
transactions.push(transaction);
3131
}
3232

3333
transactions.forEach(transaction => {
34-
totalOverall += transaction.value
35-
if (transaction.type === 'cash') {
36-
totalCash += transaction.value
34+
totalOverall += transaction.value;
35+
if (transaction.type === "cash") {
36+
totalCash += transaction.value;
3737
} else {
38-
totalCreditCard += transaction.value
38+
totalCreditCard += transaction.value;
3939
}
40-
})
40+
});
4141

42-
alert(`Total by cash: $ ${totalCash}`)
43-
alert(`Total by credit card: $ ${totalCreditCard}`)
44-
alert(`Total overall: $ ${totalOverall}`)
42+
alert(`Total by cash: $ ${totalCash}`);
43+
alert(`Total by credit card: $ ${totalCreditCard}`);
44+
alert(`Total overall: $ ${totalOverall}`);
4545

4646
transactions.forEach(transaction => {
47-
if (transaction.type !== 'cash') {
47+
if (transaction.type !== "cash") {
4848
alert(
4949
`First installment of transaction ${transaction.id}: $ ${(
5050
transaction.value / 3
5151
).toFixed(2)}`
52-
)
52+
);
5353
}
54-
})
54+
});

source/scripts/ex2.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
const num = prompt('Insert a positive integer: ')
1+
const num = prompt("Insert a positive integer: ");
22
if (isNaN(num)) {
3-
alert('Not a number!')
3+
alert("Not a number!");
44
} else if (num % 1 !== 0) {
5-
alert('Not an integer!')
5+
alert("Not an integer!");
66
} else if (num <= 0) {
7-
alert('Not a positive integer (exclusive)!')
7+
alert("Not a positive integer (exclusive)!");
88
} else {
9-
let i = 0
10-
let s = 0
11-
let equation = 'S = '
9+
let i = 0;
10+
let s = 0;
11+
let equation = "S = ";
1212
for (i = 1; i <= num; i++) {
13-
s += 1 / i
13+
s += 1 / i;
1414
if (i < num) {
15-
equation += `1/${i} + `
15+
equation += `1/${i} + `;
1616
} else {
17-
equation += `1/${i} =>`
17+
equation += `1/${i} =>`;
1818
}
1919
}
20-
document.write(`${equation}<br>S = ${s}<br>`)
20+
document.write(`${equation}<br>S = ${s}<br>`);
2121
}

source/scripts/ex3.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
for (let i = 1; i <= 10; i++) {
2-
document.write(`${i} times table<br><br>`)
2+
document.write(`${i} times table<br><br>`);
33
for (let j = 1; j <= 10; j++) {
4-
document.write(`${j} * ${i} = ${j * i}<br>`)
4+
document.write(`${j} * ${i} = ${j * i}<br>`);
55
}
6-
document.write('<br>')
6+
document.write("<br>");
77
}

source/scripts/ex4.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,18 @@ let groups = [
44
[0, 0, 0, 0],
55
[0, 0, 0, 0],
66
[0, 0, 0, 0]
7-
]
7+
];
88
groups.forEach((group, groupIndex) => {
99
group.forEach((value, index, group) => {
10-
group[index] = prompt(`Insert number ${index + 1} for group ${groupIndex + 1}`)
11-
})
12-
})
10+
group[index] = prompt(
11+
`Insert number ${index + 1} for group ${groupIndex + 1}`
12+
);
13+
});
14+
});
1315
groups.forEach((group, groupIndex) => {
14-
document.write(`Group ${groupIndex + 1}<br><br>`)
16+
document.write(`Group ${groupIndex + 1}<br><br>`);
1517
group.forEach((value, index) => {
16-
document.write(`groups[${groupIndex}][${index}] = ${value}<br>`)
17-
})
18-
document.write('<br>')
19-
})
18+
document.write(`groups[${groupIndex}][${index}] = ${value}<br>`);
19+
});
20+
document.write("<br>");
21+
});

source/scripts/ex5.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
const body = document.querySelector('body')
2-
const clients = []
3-
let i = 0
1+
const body = document.querySelector("body");
2+
const clients = [];
3+
let i = 0;
44
do {
55
const client = {
6-
name: '',
6+
name: "",
77
money: 0,
88
discount: 0
9-
}
10-
client.name = prompt(`Enter name for client no. ${i + 1}: `)
11-
client.money = prompt(`Enter money spent for client no. ${i + 1}: `)
9+
};
10+
client.name = prompt(`Enter name for client no. ${i + 1}: `);
11+
client.money = prompt(`Enter money spent for client no. ${i + 1}: `);
1212
if (client.money < 1000) {
13-
client.discount = client.money * 0.1
13+
client.discount = client.money * 0.1;
1414
} else {
15-
client.discount = client.money * 0.15
15+
client.discount = client.money * 0.15;
1616
}
17-
clients.push(client)
18-
i++
19-
} while (i < 3)
17+
clients.push(client);
18+
i++;
19+
} while (i < 3);
2020
clients.forEach(client => {
21-
body.innerHTML += `<h2>${client.name}</h2>`
22-
body.innerHTML += `<p>Money spent: ${client.money}</p>`
23-
body.innerHTML += `<p>Discount: ${client.discount}</p>`
24-
body.innerHTML += `<p>Total: ${client.money - client.discount}</p>`
25-
})
21+
body.innerHTML += `<h2>${client.name}</h2>`;
22+
body.innerHTML += `<p>Money spent: ${client.money}</p>`;
23+
body.innerHTML += `<p>Discount: ${client.discount}</p>`;
24+
body.innerHTML += `<p>Total: ${client.money - client.discount}</p>`;
25+
});

source/scripts/ex6.js

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,54 @@
11
// generate fake data
2-
const options = []
3-
let p = 5 // price
4-
let q = 120 // quantity
5-
const e = 200 // expenses
2+
const options = [];
3+
let p = 5; // price
4+
let q = 120; // quantity
5+
const e = 200; // expenses
66
while (p >= 1) {
77
options.push({
88
price: p,
99
quantity: q,
10-
profit: (p * q) - e
11-
})
12-
p -= 0.5
13-
q += 26
10+
profit: p * q - e
11+
});
12+
p -= 0.5;
13+
q += 26;
1414
}
1515

1616
// render fake data
17-
const tbody = document.querySelector('tbody')
17+
const tbody = document.querySelector("tbody");
1818
options.forEach(option => {
19-
const row = document.createElement('tr')
20-
const values = Object.values(option)
19+
const row = document.createElement("tr");
20+
const values = Object.values(option);
2121
for (const value of values) {
22-
const cell = document.createElement('td')
23-
const cellContent = document.createTextNode(`${value}`)
24-
cell.appendChild(cellContent)
25-
row.appendChild(cell)
22+
const cell = document.createElement("td");
23+
const cellContent = document.createTextNode(`${value}`);
24+
cell.appendChild(cellContent);
25+
row.appendChild(cell);
2626
}
27-
tbody.appendChild(row)
28-
})
27+
tbody.appendChild(row);
28+
});
2929

3030
// find most profitable option
3131
// po = profitableOption
3232
// co = currentOption
33-
const reducer = (po, co) => co.profit > po.profit ? co : po
34-
const profitable = options.reduce(reducer)
33+
const reducer = (po, co) => (co.profit > po.profit ? co : po);
34+
const profitable = options.reduce(reducer);
3535

3636
// render most profitable option
37-
const tblBestOption = document.querySelector('#best-option')
38-
const entries = Object.entries(profitable)
37+
const tblBestOption = document.querySelector("#best-option");
38+
const entries = Object.entries(profitable);
3939
for (const [key, value] of entries) {
4040
// row
41-
const row = document.createElement('tr')
41+
const row = document.createElement("tr");
4242
// header cell
43-
const headerCell = document.createElement('th')
44-
const headerCellContent = document.createTextNode(`${key}`)
45-
headerCell.appendChild(headerCellContent)
46-
row.appendChild(headerCell)
43+
const headerCell = document.createElement("th");
44+
const headerCellContent = document.createTextNode(`${key}`);
45+
headerCell.appendChild(headerCellContent);
46+
row.appendChild(headerCell);
4747
// standard cell
48-
const standardCell = document.createElement('td')
49-
const standardCellContent = document.createTextNode(`${value}`)
50-
standardCell.appendChild(standardCellContent)
51-
row.appendChild(standardCell)
48+
const standardCell = document.createElement("td");
49+
const standardCellContent = document.createTextNode(`${value}`);
50+
standardCell.appendChild(standardCellContent);
51+
row.appendChild(standardCell);
5252
// insert row into the table
53-
tblBestOption.appendChild(row)
53+
tblBestOption.appendChild(row);
5454
}

source/scripts/ex7.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
let count = 0
2-
let people = 0
1+
let count = 0;
2+
let people = 0;
33

44
do {
5-
const age = prompt("What's your age?")
5+
const age = prompt("What's your age?");
66
if (age >= 18) {
7-
people += 1
7+
people += 1;
88
}
9-
count++
10-
} while (count < 5)
9+
count++;
10+
} while (count < 5);
1111

12-
document.write(`<p>No. of people older than 17: ${people}</p>`)
12+
document.write(`<p>No. of people older than 17: ${people}</p>`);

source/scripts/ex8.js

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,52 @@
11
// receive age input from 15 people
2-
const people = []
2+
const people = [];
33
const ageGroups = {
44
first: [],
55
second: [],
66
third: [],
77
fourth: [],
88
fifth: []
9-
}
9+
};
1010
for (let index = 0; index < 5; index++) {
1111
// save person data in array
1212
const person = {
1313
age: 0
14-
}
15-
person.age = prompt('How many years old?')
16-
people.push(person)
14+
};
15+
person.age = prompt("How many years old?");
16+
people.push(person);
1717

1818
// classify each person based on age group
1919
if (person.age <= 15) {
20-
ageGroups.first.push(person)
20+
ageGroups.first.push(person);
2121
} else if (person.age >= 16 && person.age <= 30) {
22-
ageGroups.second.push(person)
22+
ageGroups.second.push(person);
2323
} else if (person.age >= 31 && person.age <= 45) {
24-
ageGroups.third.push(person)
24+
ageGroups.third.push(person);
2525
} else if (person.age >= 46 && person.age <= 60) {
26-
ageGroups.fourth.push(person)
26+
ageGroups.fourth.push(person);
2727
} else {
28-
ageGroups.fifth.push(person)
28+
ageGroups.fifth.push(person);
2929
}
3030
}
3131

3232
// save each age group as a key-value array
33-
const entries = Object.entries(ageGroups)
33+
const entries = Object.entries(ageGroups);
3434

3535
// show no. of people in each age group
36-
let output = '<table><thead><tr><th>Group</th><th>No. People</th></tr></thead><tbody>'
36+
let output =
37+
"<table><thead><tr><th>Group</th><th>No. People</th></tr></thead><tbody>";
3738
for (const [key, value] of entries) {
38-
output += `<tr><td>${key}</td><td>${value.length}</td></tr>`
39+
output += `<tr><td>${key}</td><td>${value.length}</td></tr>`;
3940
}
40-
output += '</tbody></table><br>'
41-
document.write(output)
41+
output += "</tbody></table><br>";
42+
document.write(output);
4243

4344
// show percentage of people in first and last age groups
44-
output = '<table><thead><tr><th>Group</th><th>%</th></tr></thead><tbody>'
45-
output += `<tr><td>First</td><td>${(entries[0][1].length / people.length) * 100}</td></tr>`
46-
output += `<tr><td>Last</td><td>${(entries[entries.length - 1][1].length / people.length) * 100}</td></tr>`
47-
output += '</tbody></table><br>'
48-
document.write(output)
45+
output = "<table><thead><tr><th>Group</th><th>%</th></tr></thead><tbody>";
46+
output += `<tr><td>First</td><td>${(entries[0][1].length / people.length) *
47+
100}</td></tr>`;
48+
output += `<tr><td>Last</td><td>${(entries[entries.length - 1][1].length /
49+
people.length) *
50+
100}</td></tr>`;
51+
output += "</tbody></table><br>";
52+
document.write(output);

0 commit comments

Comments
 (0)