Skip to content

Instantly share code, notes, and snippets.

@DarioAlessioR
Last active June 17, 2022 13:08
Show Gist options
  • Save DarioAlessioR/97ffe51fc71a00bb612451ba390d377b to your computer and use it in GitHub Desktop.
Save DarioAlessioR/97ffe51fc71a00bb612451ba390d377b to your computer and use it in GitHub Desktop.
DRY activity Microverse 3rd week 2nd Module
  • Example 1:

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]);

...

.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; }


Answer the question: "Is it DRY?" If it is not DRY, show how you can make it DRY by adding your version of the code. If it is DRY, explain why it is DRY.


  • Example 1 is not DRY.

  • My DRY code for js file:

pets.forEach(item => console.log(item));

  • My DRY code for css file:

.font-family-size { font-family: "Times New Roman", Times, serif; font-size: 1rem; }

.cat { color: #FFF; }

.dog { color: #000; }

.dragon { color: #009933; }

Example 2:

const greet = (message, name) => { console.log(${message}, ${name}!) }

greet('Hello', 'John'); greet('Hola', 'Antonio'); greet('Ciao', 'Luigi')

.greetings { font-family: Arial, sans-serif; font-size: 1.5rem; }

.greetings.english { background-color: #000; color: #FFF; } .greetings.spanish { background-color: #FFF; color: #000; }


Answer the question: "Is it DRY?" If it is not DRY, show how you can make it DRY by adding your version of the code. If it is DRY, explain why it is DRY.


  • Example 2 is DRY.

  • js is DRY because function greet avoids giving 1 console.log instruction for each item. Just 1 instruction is enough.

  • css is DRY because common properties are in only 1 class (greetings), and not repeated in each language greeting class.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment