Skip to content

Instantly share code, notes, and snippets.

@iLynette
Created February 21, 2022 12:53
Show Gist options
  • Save iLynette/e49f85217af1be43193b8c27fefe8d27 to your computer and use it in GitHub Desktop.
Save iLynette/e49f85217af1be43193b8c27fefe8d27 to your computer and use it in GitHub Desktop.
DRY exercise
const pets = ['Cat', 'Dog', 'Bird', 'Fish', 'Frog', 'Hamster', 'Pig', 'Horse', 'Lion', 'Dragon'];
// Print all pets
console.log(pets[0]);
console.log(pets[1]);
console.log(pets[2]);
console.log(pets[3]);
...
//css
.cat {
font-family: "Times New Roman", Times, serif;
font-size: 1rem;
color: #FFF;
}
.dog {
font-family: "Times New Roman", Times, serif;
font-size: 1rem;
color: #000;
}
.dragon {
font-family: "Times New Roman", Times, serif;
font-size: 1rem;
color: #009933;
}
It is not dry in that lines of code have been repeated
const pets = ['Cat', 'Dog', 'Bird', 'Fish', 'Frog', 'Hamster', 'Pig', 'Horse', 'Lion', 'Dragon'];
// Print all pets
pets.forEach(pet => console.log(pet());
//css
pets {
font-family: "Times New Roman", Times, serif;
font-size: 1rem;
}
cat{
color: #FFF;
}
dog{
color: #000;
}
dragon{
color: #009933;
}
const greet = (message, name) => {
console.log(`${message}, ${name}!`)
}
greet('Hello', 'John');
greet('Hola', 'Antonio');
greet('Ciao', 'Luigi')
//css
.greetings {
font-family: Arial, sans-serif;
font-size: 1.5rem;
}
.greetings.english {
background-color: #000;
color: #FFF;
}
.greetings.spanish {
background-color: #FFF;
color: #000;
}
It is DRY, no code has been repeated.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment