Skip to content

Instantly share code, notes, and snippets.

@EricRohlfs
Created July 15, 2021 13:59
Show Gist options
  • Save EricRohlfs/e1ba17e4b8b425050cd6b76ff398e594 to your computer and use it in GitHub Desktop.
Save EricRohlfs/e1ba17e4b8b425050cd6b76ff398e594 to your computer and use it in GitHub Desktop.
<html>
<head>
</head>
<body>
<h1></h1>
<div>My Friends</div>
<ul></ul>
</body>
<script>
// the html specification calls for having the script tag in the head, but this will error out because the body.h1 element would not rendered on the page yet
// so we put the script tag at the bottom
//only shows in the console aka developer tools
console.info("starting script")
//just a variable to play with
var myName = "Eric"
if(myName === "Eric") {
// see template literal for how I did string concatenation
document.querySelector('h1').innerHTML = `My Name is ${myName}`
}
//array or list example
var myFriends = ["John", "Paul", "Ringo", "George"]
var friendsList = myFriends.map(friend =>{
return `<li>${friend}</li>`
}).join('') // join to get rid of the comma
document.querySelector("ul").innerHTML = friendsList
console.info("all done")
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment