Last active
July 2, 2021 12:43
-
-
Save Steamforge/5bbcf400aea394846d12350bce956d32 to your computer and use it in GitHub Desktop.
A Template Literal Funciton
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// an array of colors | |
let colors = ['red', 'green', 'blue']; | |
// a function to build a list | |
let makeTemplate = function (data) { | |
let newList = ''; | |
data.forEach(function(element) { | |
newList += `<li>${element}</li>`; | |
}); | |
return newList; | |
}; | |
// build a container template | |
let template = `<ul> | |
${makeTemplate(colors)} | |
</ul>`; | |
// add the template to the page | |
document.getElementById('result').innerHTML = template; | |
/** output | |
* <ul> | |
* <li>red</li> | |
* <li>green</li> | |
* <li>blue</li> | |
* </ul> | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment