Skip to content

Instantly share code, notes, and snippets.

@i-oliva
Created July 9, 2018 17:39
Show Gist options
  • Save i-oliva/8d1dc42e538b4506f245f1c7b6d08e9e to your computer and use it in GitHub Desktop.
Save i-oliva/8d1dc42e538b4506f245f1c7b6d08e9e to your computer and use it in GitHub Desktop.
Solution to the markup to HTML exercise
function markupExercise(n) {
// Count the number of # occurrences in the file
let occurrences = n.split('#').length - 1;
// Get the different word
let arrayOfN = n.split(' ');
let differentWord = '';
for (let element of arrayOfN) {
if (element !== '#') {
differentWord = element;
}
}
// Same markup returned
let returnMarkup = n;
// Different markup returned according to the number of # occurrences (could've use case 0 as well or even better
// a for loop)
switch (occurrences) {
case 1:
returnMarkup = `<h1>${differentWord}</h1>`;
break;
case 2:
returnMarkup = `<h2>${differentWord}</h2>`;
break;
case 3:
returnMarkup = `<h3>${differentWord}</h3>`;
break;
case 4:
returnMarkup = `<h4>${differentWord}</h4>`;
break;
case 5:
returnMarkup = `<h5>${differentWord}</h5>`;
break;
case 6:
returnMarkup = `<h6>${differentWord}</h6>`
}
return returnMarkup;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment