Coding is an art, so why not make it as clean as possible? In this video, we'll cover 3 techniques we'd like to implement to make my JavaScript code more readable and extensible.
function getThemeColors() {
let currentHour = new Date().getHours();
let textColor;
let backgroundColor;
if (currentHour > 20 && currentHour < 7) {
textColor = "#ffffff";
backgroundColor = "#222222";
} else {
textColor = "#222222";
backgroundColor = "#ffffff";
}
return {
textColor: textColor,
backgroundColor: backgroundColor
};
}
const numbers = [4, 9, 2, 7, 11];
// Find factors of 12
for (const n of numbers) {
if (12 % n === 0) {
console.log(`${n} is a factor of 12!`);
}
}
const names = ["dom", "peter", "aleisha", "sam"];
const capitalized = [];
for (const n of names) {
const newName = n[0].toUpperCase() + n.slice(1);
capitalized.push(newName);
}
View the Starting Code:
https://dcode.domenade.com/tutorials/3-ways-write-clean-code-in-javascript