Changing the text of a few elements when a tile is clicked












0












$begingroup$


I have created a basic web page that contains a panel which displays some details about an object, and a panel which contains some tiles that are used to choose which object to view. The idea is straight-forward, and with plenty of C# experience, the learning curve was small. However, since I am relatively new to JavaScript, I'd like a brief code review of my JavaScript to determine if there are any gotchas or perhaps alternatives that are more graceful.






// The available titles and their associated data.
var titles = ["Pong", "Tetris", "Pac-Man", "Snake", "Super Mario", "Pokemon", "Match 3", "Blossom Blast", "Driven", "Terrible Zombies"];
var data = [
["Pong is the equivalent of Hello World in the game development industry.", "Vectors, Rendering", "Directions", "Adding obstacles.", "Add effects."]
["Tetris is an iconic title. Though I am unable to provide the greatest theme music of all time, I hope you thoroughly enjoy the remake!", "Multi-Dimensional Arrays", "Arrays of Arrays", "Creating new pieces.", "Add effects."]
["Pac-Man is an iconic title providing a lot of fun and some great concepts.", "Collision Detection", "Building the walls.", "Object pooling.", "Add more ghosts and effects."]
["Dialing it back down, Snake is another iconic title with great concepts but simple implementation.", "Collision Detection", "None", "Linked Lists", "None"]
["Another iconic title, Super Mario is known around the world.", "Parallaxing Backgrounds", "None", "None", "None"]
["Pokemon is a favorite of multiple generations, this remake is simple and for demonstrations only.", "None", "None", "None", "None"]
["This is a simple demonstration of the match three game logic.", "None", "None", "None", "None"]
["The beautiful game Blossom Blast was my inspiration to go mobile.", "None", "None", "None", "None"]
["Driven is a basic 3D driving game.", "None", "None", "None", "None"]
["Terrible zombies is just as the name states, a terrible zombie game.", "None", "None", "None", "None"]
];

function swapGame(domElement, title) {
// The tile collection.
var tileCollection = document.getElementsByClassName('tiles');
var tiles = tileCollection[0].getElementsByTagName('li');

// The labels for display.
var lblTitle = document.getElementById('dTitle');
var lblDescription = document.getElementById('dDescription');
var lblConcepts = document.getElementById('dConcepts');
var lblChallenges = document.getElementById('dChallenges');
var lblAdvanced = document.getElementById('dAdvanced');
var lblHomework = document.getElementById('dHomework');
for (var i = 0; i < tiles.length; i++)
tiles[i].className = '';

domElement.classList.toggle('active');

lblTitle.innerHTML = title;

var id = titles.indexOf(title);
lblDescription.innerHTML = data[id][0];
lblConcepts.innerHTML = 'Concepts: ' + data[id][1];
lblChallenges.innerHTML = 'Challenges: ' + data[id][2];
lblAdvanced.innerHTML = 'Advanced: ' + data[id][3];
lblAdvanced.innerHTML = 'Homework: ' + data[id][4];
}

.tile-container {
width: 100%;
height: 100%;
display: flex;
}

.view-panel {
width: 30%;
box-shadow: 0px 5px 15px #111;
background-color: #fff;
color: #333;
padding: 5px;
}

.launch-button {
background-color: #fc0;
border-radius: 5px;
height: 50px;
width: 95%;
margin: auto;
cursor: wait;
transition: 0.5s all;
}

.launch-button:hover {
background-color: #da0;
}

.launch-button a {
text-decoration: none;
color: #333;
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
}

.tiles {
width: 70%;
display: flex;
align-items: flex-start;
justify-content: flex-start;
}

.tile-view {
list-style: none;
width: 100%;
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: center;
padding: 0;
}

.tile-view li {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
will-change: all;
width: 150px;
height: 150px;
cursor: pointer;
transition: 0.5s background-color;
margin-left: 5px;
margin: 5px;
background-color: #222;
color: #eee;
box-shadow: 2px 2px 5px #111;
}

.tile-view li>a {
color: #eee;
text-decoration: none;
}

.tile-view li:hover {
background-color: #fc0;
box-shadow: 5px 5px 15px #111;
}

.tile-view li.active {
background-color: #fc0;
}

.tile-view li.active,
.tile-view li.active>a,
.tile-view li:hover,
.tile-view li:hover>a {
color: #333;
}

@media screen and (max-width: 750px) {
.view-panel {
display: none;
}
.tiles {
width: 100%;
}
.tile-view li {
width: 300px;
}
}

<div class="tile-container">
<div class="view-panel">
<h1 id="dTitle">Pong</h1>
<p id="dDescription">Pong is the equivalent of Hello World in the game development industry.</p>
<ul>
<li><span id="dConcepts">Concepts: Vectors, Rendering</span></li>
<li><span id="dChallenges">Challenges: Directions</span></li>
<li><span id="dAdvanced">Advanced: Adding obstacles.</span></li>
<li><span id="dHomework">Homework: Add effects.</span></li>
</ul>
<div class="launch-button"><a href="#">Launch</a></div>
</div>
<div class="tiles">
<ul class="tile-view">
<li onclick="swapGame(this, 'Pong')" class="active">
<i class="fas fa-gamepad" aria-hidden="true"></i>
<a href="#">Pong</a>
</li>
<li onclick="swapGame(this, 'Tetris')">
<i class="fas fa-gamepad" aria-hidden="true"></i>
<a href="#">Tetris</a>
</li>
<li onclick="swapGame(this, 'Pac-Man')">
<i class="fas fa-gamepad" aria-hidden="true"></i>
<a href="#">Pac-Man</a>
</li>
<li onclick="swapGame(this, 'Snake')">
<i class="fas fa-gamepad" aria-hidden="true"></i>
<a href="#">Snake</a>
</li>
<li onclick="swapGame(this, 'Super Mario')">
<i class="fas fa-gamepad" aria-hidden="true"></i>
<a href="#">Super Mario</a>
</li>
<li onclick="swapGame(this, 'Pokemon')">
<i class="fas fa-gamepad" aria-hidden="true"></i>
<a href="#">Pokemon</a>
</li>
<li onclick="swapGame(this, 'Match 3')">
<i class="fas fa-gamepad" aria-hidden="true"></i>
<a href="#">Match 3</a>
</li>
<li onclick="swapGame(this, 'Blossom Blast')">
<i class="fas fa-gamepad" aria-hidden="true"></i>
<a href="#">Blossom Blast</a>
</li>
<li onclick="swapGame(this, 'Driven')">
<i class="fas fa-gamepad" aria-hidden="true"></i>
<a href="#">Driven</a>
</li>
<li onclick="swapGame(this, 'Terrible Zombies')">
<i class="fas fa-gamepad" aria-hidden="true"></i>
<a href="#">Terrible Zombies</a>
</li>
</ul>
</div>
</div>












share|improve this question











$endgroup$












  • $begingroup$
    Is there a reason why you want the text to be partly stored in the JavaScript code and partly in the HTML, rather than all in JavaScript or all in HTML?
    $endgroup$
    – 200_success
    5 mins ago
















0












$begingroup$


I have created a basic web page that contains a panel which displays some details about an object, and a panel which contains some tiles that are used to choose which object to view. The idea is straight-forward, and with plenty of C# experience, the learning curve was small. However, since I am relatively new to JavaScript, I'd like a brief code review of my JavaScript to determine if there are any gotchas or perhaps alternatives that are more graceful.






// The available titles and their associated data.
var titles = ["Pong", "Tetris", "Pac-Man", "Snake", "Super Mario", "Pokemon", "Match 3", "Blossom Blast", "Driven", "Terrible Zombies"];
var data = [
["Pong is the equivalent of Hello World in the game development industry.", "Vectors, Rendering", "Directions", "Adding obstacles.", "Add effects."]
["Tetris is an iconic title. Though I am unable to provide the greatest theme music of all time, I hope you thoroughly enjoy the remake!", "Multi-Dimensional Arrays", "Arrays of Arrays", "Creating new pieces.", "Add effects."]
["Pac-Man is an iconic title providing a lot of fun and some great concepts.", "Collision Detection", "Building the walls.", "Object pooling.", "Add more ghosts and effects."]
["Dialing it back down, Snake is another iconic title with great concepts but simple implementation.", "Collision Detection", "None", "Linked Lists", "None"]
["Another iconic title, Super Mario is known around the world.", "Parallaxing Backgrounds", "None", "None", "None"]
["Pokemon is a favorite of multiple generations, this remake is simple and for demonstrations only.", "None", "None", "None", "None"]
["This is a simple demonstration of the match three game logic.", "None", "None", "None", "None"]
["The beautiful game Blossom Blast was my inspiration to go mobile.", "None", "None", "None", "None"]
["Driven is a basic 3D driving game.", "None", "None", "None", "None"]
["Terrible zombies is just as the name states, a terrible zombie game.", "None", "None", "None", "None"]
];

function swapGame(domElement, title) {
// The tile collection.
var tileCollection = document.getElementsByClassName('tiles');
var tiles = tileCollection[0].getElementsByTagName('li');

// The labels for display.
var lblTitle = document.getElementById('dTitle');
var lblDescription = document.getElementById('dDescription');
var lblConcepts = document.getElementById('dConcepts');
var lblChallenges = document.getElementById('dChallenges');
var lblAdvanced = document.getElementById('dAdvanced');
var lblHomework = document.getElementById('dHomework');
for (var i = 0; i < tiles.length; i++)
tiles[i].className = '';

domElement.classList.toggle('active');

lblTitle.innerHTML = title;

var id = titles.indexOf(title);
lblDescription.innerHTML = data[id][0];
lblConcepts.innerHTML = 'Concepts: ' + data[id][1];
lblChallenges.innerHTML = 'Challenges: ' + data[id][2];
lblAdvanced.innerHTML = 'Advanced: ' + data[id][3];
lblAdvanced.innerHTML = 'Homework: ' + data[id][4];
}

.tile-container {
width: 100%;
height: 100%;
display: flex;
}

.view-panel {
width: 30%;
box-shadow: 0px 5px 15px #111;
background-color: #fff;
color: #333;
padding: 5px;
}

.launch-button {
background-color: #fc0;
border-radius: 5px;
height: 50px;
width: 95%;
margin: auto;
cursor: wait;
transition: 0.5s all;
}

.launch-button:hover {
background-color: #da0;
}

.launch-button a {
text-decoration: none;
color: #333;
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
}

.tiles {
width: 70%;
display: flex;
align-items: flex-start;
justify-content: flex-start;
}

.tile-view {
list-style: none;
width: 100%;
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: center;
padding: 0;
}

.tile-view li {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
will-change: all;
width: 150px;
height: 150px;
cursor: pointer;
transition: 0.5s background-color;
margin-left: 5px;
margin: 5px;
background-color: #222;
color: #eee;
box-shadow: 2px 2px 5px #111;
}

.tile-view li>a {
color: #eee;
text-decoration: none;
}

.tile-view li:hover {
background-color: #fc0;
box-shadow: 5px 5px 15px #111;
}

.tile-view li.active {
background-color: #fc0;
}

.tile-view li.active,
.tile-view li.active>a,
.tile-view li:hover,
.tile-view li:hover>a {
color: #333;
}

@media screen and (max-width: 750px) {
.view-panel {
display: none;
}
.tiles {
width: 100%;
}
.tile-view li {
width: 300px;
}
}

<div class="tile-container">
<div class="view-panel">
<h1 id="dTitle">Pong</h1>
<p id="dDescription">Pong is the equivalent of Hello World in the game development industry.</p>
<ul>
<li><span id="dConcepts">Concepts: Vectors, Rendering</span></li>
<li><span id="dChallenges">Challenges: Directions</span></li>
<li><span id="dAdvanced">Advanced: Adding obstacles.</span></li>
<li><span id="dHomework">Homework: Add effects.</span></li>
</ul>
<div class="launch-button"><a href="#">Launch</a></div>
</div>
<div class="tiles">
<ul class="tile-view">
<li onclick="swapGame(this, 'Pong')" class="active">
<i class="fas fa-gamepad" aria-hidden="true"></i>
<a href="#">Pong</a>
</li>
<li onclick="swapGame(this, 'Tetris')">
<i class="fas fa-gamepad" aria-hidden="true"></i>
<a href="#">Tetris</a>
</li>
<li onclick="swapGame(this, 'Pac-Man')">
<i class="fas fa-gamepad" aria-hidden="true"></i>
<a href="#">Pac-Man</a>
</li>
<li onclick="swapGame(this, 'Snake')">
<i class="fas fa-gamepad" aria-hidden="true"></i>
<a href="#">Snake</a>
</li>
<li onclick="swapGame(this, 'Super Mario')">
<i class="fas fa-gamepad" aria-hidden="true"></i>
<a href="#">Super Mario</a>
</li>
<li onclick="swapGame(this, 'Pokemon')">
<i class="fas fa-gamepad" aria-hidden="true"></i>
<a href="#">Pokemon</a>
</li>
<li onclick="swapGame(this, 'Match 3')">
<i class="fas fa-gamepad" aria-hidden="true"></i>
<a href="#">Match 3</a>
</li>
<li onclick="swapGame(this, 'Blossom Blast')">
<i class="fas fa-gamepad" aria-hidden="true"></i>
<a href="#">Blossom Blast</a>
</li>
<li onclick="swapGame(this, 'Driven')">
<i class="fas fa-gamepad" aria-hidden="true"></i>
<a href="#">Driven</a>
</li>
<li onclick="swapGame(this, 'Terrible Zombies')">
<i class="fas fa-gamepad" aria-hidden="true"></i>
<a href="#">Terrible Zombies</a>
</li>
</ul>
</div>
</div>












share|improve this question











$endgroup$












  • $begingroup$
    Is there a reason why you want the text to be partly stored in the JavaScript code and partly in the HTML, rather than all in JavaScript or all in HTML?
    $endgroup$
    – 200_success
    5 mins ago














0












0








0





$begingroup$


I have created a basic web page that contains a panel which displays some details about an object, and a panel which contains some tiles that are used to choose which object to view. The idea is straight-forward, and with plenty of C# experience, the learning curve was small. However, since I am relatively new to JavaScript, I'd like a brief code review of my JavaScript to determine if there are any gotchas or perhaps alternatives that are more graceful.






// The available titles and their associated data.
var titles = ["Pong", "Tetris", "Pac-Man", "Snake", "Super Mario", "Pokemon", "Match 3", "Blossom Blast", "Driven", "Terrible Zombies"];
var data = [
["Pong is the equivalent of Hello World in the game development industry.", "Vectors, Rendering", "Directions", "Adding obstacles.", "Add effects."]
["Tetris is an iconic title. Though I am unable to provide the greatest theme music of all time, I hope you thoroughly enjoy the remake!", "Multi-Dimensional Arrays", "Arrays of Arrays", "Creating new pieces.", "Add effects."]
["Pac-Man is an iconic title providing a lot of fun and some great concepts.", "Collision Detection", "Building the walls.", "Object pooling.", "Add more ghosts and effects."]
["Dialing it back down, Snake is another iconic title with great concepts but simple implementation.", "Collision Detection", "None", "Linked Lists", "None"]
["Another iconic title, Super Mario is known around the world.", "Parallaxing Backgrounds", "None", "None", "None"]
["Pokemon is a favorite of multiple generations, this remake is simple and for demonstrations only.", "None", "None", "None", "None"]
["This is a simple demonstration of the match three game logic.", "None", "None", "None", "None"]
["The beautiful game Blossom Blast was my inspiration to go mobile.", "None", "None", "None", "None"]
["Driven is a basic 3D driving game.", "None", "None", "None", "None"]
["Terrible zombies is just as the name states, a terrible zombie game.", "None", "None", "None", "None"]
];

function swapGame(domElement, title) {
// The tile collection.
var tileCollection = document.getElementsByClassName('tiles');
var tiles = tileCollection[0].getElementsByTagName('li');

// The labels for display.
var lblTitle = document.getElementById('dTitle');
var lblDescription = document.getElementById('dDescription');
var lblConcepts = document.getElementById('dConcepts');
var lblChallenges = document.getElementById('dChallenges');
var lblAdvanced = document.getElementById('dAdvanced');
var lblHomework = document.getElementById('dHomework');
for (var i = 0; i < tiles.length; i++)
tiles[i].className = '';

domElement.classList.toggle('active');

lblTitle.innerHTML = title;

var id = titles.indexOf(title);
lblDescription.innerHTML = data[id][0];
lblConcepts.innerHTML = 'Concepts: ' + data[id][1];
lblChallenges.innerHTML = 'Challenges: ' + data[id][2];
lblAdvanced.innerHTML = 'Advanced: ' + data[id][3];
lblAdvanced.innerHTML = 'Homework: ' + data[id][4];
}

.tile-container {
width: 100%;
height: 100%;
display: flex;
}

.view-panel {
width: 30%;
box-shadow: 0px 5px 15px #111;
background-color: #fff;
color: #333;
padding: 5px;
}

.launch-button {
background-color: #fc0;
border-radius: 5px;
height: 50px;
width: 95%;
margin: auto;
cursor: wait;
transition: 0.5s all;
}

.launch-button:hover {
background-color: #da0;
}

.launch-button a {
text-decoration: none;
color: #333;
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
}

.tiles {
width: 70%;
display: flex;
align-items: flex-start;
justify-content: flex-start;
}

.tile-view {
list-style: none;
width: 100%;
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: center;
padding: 0;
}

.tile-view li {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
will-change: all;
width: 150px;
height: 150px;
cursor: pointer;
transition: 0.5s background-color;
margin-left: 5px;
margin: 5px;
background-color: #222;
color: #eee;
box-shadow: 2px 2px 5px #111;
}

.tile-view li>a {
color: #eee;
text-decoration: none;
}

.tile-view li:hover {
background-color: #fc0;
box-shadow: 5px 5px 15px #111;
}

.tile-view li.active {
background-color: #fc0;
}

.tile-view li.active,
.tile-view li.active>a,
.tile-view li:hover,
.tile-view li:hover>a {
color: #333;
}

@media screen and (max-width: 750px) {
.view-panel {
display: none;
}
.tiles {
width: 100%;
}
.tile-view li {
width: 300px;
}
}

<div class="tile-container">
<div class="view-panel">
<h1 id="dTitle">Pong</h1>
<p id="dDescription">Pong is the equivalent of Hello World in the game development industry.</p>
<ul>
<li><span id="dConcepts">Concepts: Vectors, Rendering</span></li>
<li><span id="dChallenges">Challenges: Directions</span></li>
<li><span id="dAdvanced">Advanced: Adding obstacles.</span></li>
<li><span id="dHomework">Homework: Add effects.</span></li>
</ul>
<div class="launch-button"><a href="#">Launch</a></div>
</div>
<div class="tiles">
<ul class="tile-view">
<li onclick="swapGame(this, 'Pong')" class="active">
<i class="fas fa-gamepad" aria-hidden="true"></i>
<a href="#">Pong</a>
</li>
<li onclick="swapGame(this, 'Tetris')">
<i class="fas fa-gamepad" aria-hidden="true"></i>
<a href="#">Tetris</a>
</li>
<li onclick="swapGame(this, 'Pac-Man')">
<i class="fas fa-gamepad" aria-hidden="true"></i>
<a href="#">Pac-Man</a>
</li>
<li onclick="swapGame(this, 'Snake')">
<i class="fas fa-gamepad" aria-hidden="true"></i>
<a href="#">Snake</a>
</li>
<li onclick="swapGame(this, 'Super Mario')">
<i class="fas fa-gamepad" aria-hidden="true"></i>
<a href="#">Super Mario</a>
</li>
<li onclick="swapGame(this, 'Pokemon')">
<i class="fas fa-gamepad" aria-hidden="true"></i>
<a href="#">Pokemon</a>
</li>
<li onclick="swapGame(this, 'Match 3')">
<i class="fas fa-gamepad" aria-hidden="true"></i>
<a href="#">Match 3</a>
</li>
<li onclick="swapGame(this, 'Blossom Blast')">
<i class="fas fa-gamepad" aria-hidden="true"></i>
<a href="#">Blossom Blast</a>
</li>
<li onclick="swapGame(this, 'Driven')">
<i class="fas fa-gamepad" aria-hidden="true"></i>
<a href="#">Driven</a>
</li>
<li onclick="swapGame(this, 'Terrible Zombies')">
<i class="fas fa-gamepad" aria-hidden="true"></i>
<a href="#">Terrible Zombies</a>
</li>
</ul>
</div>
</div>












share|improve this question











$endgroup$




I have created a basic web page that contains a panel which displays some details about an object, and a panel which contains some tiles that are used to choose which object to view. The idea is straight-forward, and with plenty of C# experience, the learning curve was small. However, since I am relatively new to JavaScript, I'd like a brief code review of my JavaScript to determine if there are any gotchas or perhaps alternatives that are more graceful.






// The available titles and their associated data.
var titles = ["Pong", "Tetris", "Pac-Man", "Snake", "Super Mario", "Pokemon", "Match 3", "Blossom Blast", "Driven", "Terrible Zombies"];
var data = [
["Pong is the equivalent of Hello World in the game development industry.", "Vectors, Rendering", "Directions", "Adding obstacles.", "Add effects."]
["Tetris is an iconic title. Though I am unable to provide the greatest theme music of all time, I hope you thoroughly enjoy the remake!", "Multi-Dimensional Arrays", "Arrays of Arrays", "Creating new pieces.", "Add effects."]
["Pac-Man is an iconic title providing a lot of fun and some great concepts.", "Collision Detection", "Building the walls.", "Object pooling.", "Add more ghosts and effects."]
["Dialing it back down, Snake is another iconic title with great concepts but simple implementation.", "Collision Detection", "None", "Linked Lists", "None"]
["Another iconic title, Super Mario is known around the world.", "Parallaxing Backgrounds", "None", "None", "None"]
["Pokemon is a favorite of multiple generations, this remake is simple and for demonstrations only.", "None", "None", "None", "None"]
["This is a simple demonstration of the match three game logic.", "None", "None", "None", "None"]
["The beautiful game Blossom Blast was my inspiration to go mobile.", "None", "None", "None", "None"]
["Driven is a basic 3D driving game.", "None", "None", "None", "None"]
["Terrible zombies is just as the name states, a terrible zombie game.", "None", "None", "None", "None"]
];

function swapGame(domElement, title) {
// The tile collection.
var tileCollection = document.getElementsByClassName('tiles');
var tiles = tileCollection[0].getElementsByTagName('li');

// The labels for display.
var lblTitle = document.getElementById('dTitle');
var lblDescription = document.getElementById('dDescription');
var lblConcepts = document.getElementById('dConcepts');
var lblChallenges = document.getElementById('dChallenges');
var lblAdvanced = document.getElementById('dAdvanced');
var lblHomework = document.getElementById('dHomework');
for (var i = 0; i < tiles.length; i++)
tiles[i].className = '';

domElement.classList.toggle('active');

lblTitle.innerHTML = title;

var id = titles.indexOf(title);
lblDescription.innerHTML = data[id][0];
lblConcepts.innerHTML = 'Concepts: ' + data[id][1];
lblChallenges.innerHTML = 'Challenges: ' + data[id][2];
lblAdvanced.innerHTML = 'Advanced: ' + data[id][3];
lblAdvanced.innerHTML = 'Homework: ' + data[id][4];
}

.tile-container {
width: 100%;
height: 100%;
display: flex;
}

.view-panel {
width: 30%;
box-shadow: 0px 5px 15px #111;
background-color: #fff;
color: #333;
padding: 5px;
}

.launch-button {
background-color: #fc0;
border-radius: 5px;
height: 50px;
width: 95%;
margin: auto;
cursor: wait;
transition: 0.5s all;
}

.launch-button:hover {
background-color: #da0;
}

.launch-button a {
text-decoration: none;
color: #333;
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
}

.tiles {
width: 70%;
display: flex;
align-items: flex-start;
justify-content: flex-start;
}

.tile-view {
list-style: none;
width: 100%;
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: center;
padding: 0;
}

.tile-view li {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
will-change: all;
width: 150px;
height: 150px;
cursor: pointer;
transition: 0.5s background-color;
margin-left: 5px;
margin: 5px;
background-color: #222;
color: #eee;
box-shadow: 2px 2px 5px #111;
}

.tile-view li>a {
color: #eee;
text-decoration: none;
}

.tile-view li:hover {
background-color: #fc0;
box-shadow: 5px 5px 15px #111;
}

.tile-view li.active {
background-color: #fc0;
}

.tile-view li.active,
.tile-view li.active>a,
.tile-view li:hover,
.tile-view li:hover>a {
color: #333;
}

@media screen and (max-width: 750px) {
.view-panel {
display: none;
}
.tiles {
width: 100%;
}
.tile-view li {
width: 300px;
}
}

<div class="tile-container">
<div class="view-panel">
<h1 id="dTitle">Pong</h1>
<p id="dDescription">Pong is the equivalent of Hello World in the game development industry.</p>
<ul>
<li><span id="dConcepts">Concepts: Vectors, Rendering</span></li>
<li><span id="dChallenges">Challenges: Directions</span></li>
<li><span id="dAdvanced">Advanced: Adding obstacles.</span></li>
<li><span id="dHomework">Homework: Add effects.</span></li>
</ul>
<div class="launch-button"><a href="#">Launch</a></div>
</div>
<div class="tiles">
<ul class="tile-view">
<li onclick="swapGame(this, 'Pong')" class="active">
<i class="fas fa-gamepad" aria-hidden="true"></i>
<a href="#">Pong</a>
</li>
<li onclick="swapGame(this, 'Tetris')">
<i class="fas fa-gamepad" aria-hidden="true"></i>
<a href="#">Tetris</a>
</li>
<li onclick="swapGame(this, 'Pac-Man')">
<i class="fas fa-gamepad" aria-hidden="true"></i>
<a href="#">Pac-Man</a>
</li>
<li onclick="swapGame(this, 'Snake')">
<i class="fas fa-gamepad" aria-hidden="true"></i>
<a href="#">Snake</a>
</li>
<li onclick="swapGame(this, 'Super Mario')">
<i class="fas fa-gamepad" aria-hidden="true"></i>
<a href="#">Super Mario</a>
</li>
<li onclick="swapGame(this, 'Pokemon')">
<i class="fas fa-gamepad" aria-hidden="true"></i>
<a href="#">Pokemon</a>
</li>
<li onclick="swapGame(this, 'Match 3')">
<i class="fas fa-gamepad" aria-hidden="true"></i>
<a href="#">Match 3</a>
</li>
<li onclick="swapGame(this, 'Blossom Blast')">
<i class="fas fa-gamepad" aria-hidden="true"></i>
<a href="#">Blossom Blast</a>
</li>
<li onclick="swapGame(this, 'Driven')">
<i class="fas fa-gamepad" aria-hidden="true"></i>
<a href="#">Driven</a>
</li>
<li onclick="swapGame(this, 'Terrible Zombies')">
<i class="fas fa-gamepad" aria-hidden="true"></i>
<a href="#">Terrible Zombies</a>
</li>
</ul>
</div>
</div>








// The available titles and their associated data.
var titles = ["Pong", "Tetris", "Pac-Man", "Snake", "Super Mario", "Pokemon", "Match 3", "Blossom Blast", "Driven", "Terrible Zombies"];
var data = [
["Pong is the equivalent of Hello World in the game development industry.", "Vectors, Rendering", "Directions", "Adding obstacles.", "Add effects."]
["Tetris is an iconic title. Though I am unable to provide the greatest theme music of all time, I hope you thoroughly enjoy the remake!", "Multi-Dimensional Arrays", "Arrays of Arrays", "Creating new pieces.", "Add effects."]
["Pac-Man is an iconic title providing a lot of fun and some great concepts.", "Collision Detection", "Building the walls.", "Object pooling.", "Add more ghosts and effects."]
["Dialing it back down, Snake is another iconic title with great concepts but simple implementation.", "Collision Detection", "None", "Linked Lists", "None"]
["Another iconic title, Super Mario is known around the world.", "Parallaxing Backgrounds", "None", "None", "None"]
["Pokemon is a favorite of multiple generations, this remake is simple and for demonstrations only.", "None", "None", "None", "None"]
["This is a simple demonstration of the match three game logic.", "None", "None", "None", "None"]
["The beautiful game Blossom Blast was my inspiration to go mobile.", "None", "None", "None", "None"]
["Driven is a basic 3D driving game.", "None", "None", "None", "None"]
["Terrible zombies is just as the name states, a terrible zombie game.", "None", "None", "None", "None"]
];

function swapGame(domElement, title) {
// The tile collection.
var tileCollection = document.getElementsByClassName('tiles');
var tiles = tileCollection[0].getElementsByTagName('li');

// The labels for display.
var lblTitle = document.getElementById('dTitle');
var lblDescription = document.getElementById('dDescription');
var lblConcepts = document.getElementById('dConcepts');
var lblChallenges = document.getElementById('dChallenges');
var lblAdvanced = document.getElementById('dAdvanced');
var lblHomework = document.getElementById('dHomework');
for (var i = 0; i < tiles.length; i++)
tiles[i].className = '';

domElement.classList.toggle('active');

lblTitle.innerHTML = title;

var id = titles.indexOf(title);
lblDescription.innerHTML = data[id][0];
lblConcepts.innerHTML = 'Concepts: ' + data[id][1];
lblChallenges.innerHTML = 'Challenges: ' + data[id][2];
lblAdvanced.innerHTML = 'Advanced: ' + data[id][3];
lblAdvanced.innerHTML = 'Homework: ' + data[id][4];
}

.tile-container {
width: 100%;
height: 100%;
display: flex;
}

.view-panel {
width: 30%;
box-shadow: 0px 5px 15px #111;
background-color: #fff;
color: #333;
padding: 5px;
}

.launch-button {
background-color: #fc0;
border-radius: 5px;
height: 50px;
width: 95%;
margin: auto;
cursor: wait;
transition: 0.5s all;
}

.launch-button:hover {
background-color: #da0;
}

.launch-button a {
text-decoration: none;
color: #333;
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
}

.tiles {
width: 70%;
display: flex;
align-items: flex-start;
justify-content: flex-start;
}

.tile-view {
list-style: none;
width: 100%;
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: center;
padding: 0;
}

.tile-view li {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
will-change: all;
width: 150px;
height: 150px;
cursor: pointer;
transition: 0.5s background-color;
margin-left: 5px;
margin: 5px;
background-color: #222;
color: #eee;
box-shadow: 2px 2px 5px #111;
}

.tile-view li>a {
color: #eee;
text-decoration: none;
}

.tile-view li:hover {
background-color: #fc0;
box-shadow: 5px 5px 15px #111;
}

.tile-view li.active {
background-color: #fc0;
}

.tile-view li.active,
.tile-view li.active>a,
.tile-view li:hover,
.tile-view li:hover>a {
color: #333;
}

@media screen and (max-width: 750px) {
.view-panel {
display: none;
}
.tiles {
width: 100%;
}
.tile-view li {
width: 300px;
}
}

<div class="tile-container">
<div class="view-panel">
<h1 id="dTitle">Pong</h1>
<p id="dDescription">Pong is the equivalent of Hello World in the game development industry.</p>
<ul>
<li><span id="dConcepts">Concepts: Vectors, Rendering</span></li>
<li><span id="dChallenges">Challenges: Directions</span></li>
<li><span id="dAdvanced">Advanced: Adding obstacles.</span></li>
<li><span id="dHomework">Homework: Add effects.</span></li>
</ul>
<div class="launch-button"><a href="#">Launch</a></div>
</div>
<div class="tiles">
<ul class="tile-view">
<li onclick="swapGame(this, 'Pong')" class="active">
<i class="fas fa-gamepad" aria-hidden="true"></i>
<a href="#">Pong</a>
</li>
<li onclick="swapGame(this, 'Tetris')">
<i class="fas fa-gamepad" aria-hidden="true"></i>
<a href="#">Tetris</a>
</li>
<li onclick="swapGame(this, 'Pac-Man')">
<i class="fas fa-gamepad" aria-hidden="true"></i>
<a href="#">Pac-Man</a>
</li>
<li onclick="swapGame(this, 'Snake')">
<i class="fas fa-gamepad" aria-hidden="true"></i>
<a href="#">Snake</a>
</li>
<li onclick="swapGame(this, 'Super Mario')">
<i class="fas fa-gamepad" aria-hidden="true"></i>
<a href="#">Super Mario</a>
</li>
<li onclick="swapGame(this, 'Pokemon')">
<i class="fas fa-gamepad" aria-hidden="true"></i>
<a href="#">Pokemon</a>
</li>
<li onclick="swapGame(this, 'Match 3')">
<i class="fas fa-gamepad" aria-hidden="true"></i>
<a href="#">Match 3</a>
</li>
<li onclick="swapGame(this, 'Blossom Blast')">
<i class="fas fa-gamepad" aria-hidden="true"></i>
<a href="#">Blossom Blast</a>
</li>
<li onclick="swapGame(this, 'Driven')">
<i class="fas fa-gamepad" aria-hidden="true"></i>
<a href="#">Driven</a>
</li>
<li onclick="swapGame(this, 'Terrible Zombies')">
<i class="fas fa-gamepad" aria-hidden="true"></i>
<a href="#">Terrible Zombies</a>
</li>
</ul>
</div>
</div>





// The available titles and their associated data.
var titles = ["Pong", "Tetris", "Pac-Man", "Snake", "Super Mario", "Pokemon", "Match 3", "Blossom Blast", "Driven", "Terrible Zombies"];
var data = [
["Pong is the equivalent of Hello World in the game development industry.", "Vectors, Rendering", "Directions", "Adding obstacles.", "Add effects."]
["Tetris is an iconic title. Though I am unable to provide the greatest theme music of all time, I hope you thoroughly enjoy the remake!", "Multi-Dimensional Arrays", "Arrays of Arrays", "Creating new pieces.", "Add effects."]
["Pac-Man is an iconic title providing a lot of fun and some great concepts.", "Collision Detection", "Building the walls.", "Object pooling.", "Add more ghosts and effects."]
["Dialing it back down, Snake is another iconic title with great concepts but simple implementation.", "Collision Detection", "None", "Linked Lists", "None"]
["Another iconic title, Super Mario is known around the world.", "Parallaxing Backgrounds", "None", "None", "None"]
["Pokemon is a favorite of multiple generations, this remake is simple and for demonstrations only.", "None", "None", "None", "None"]
["This is a simple demonstration of the match three game logic.", "None", "None", "None", "None"]
["The beautiful game Blossom Blast was my inspiration to go mobile.", "None", "None", "None", "None"]
["Driven is a basic 3D driving game.", "None", "None", "None", "None"]
["Terrible zombies is just as the name states, a terrible zombie game.", "None", "None", "None", "None"]
];

function swapGame(domElement, title) {
// The tile collection.
var tileCollection = document.getElementsByClassName('tiles');
var tiles = tileCollection[0].getElementsByTagName('li');

// The labels for display.
var lblTitle = document.getElementById('dTitle');
var lblDescription = document.getElementById('dDescription');
var lblConcepts = document.getElementById('dConcepts');
var lblChallenges = document.getElementById('dChallenges');
var lblAdvanced = document.getElementById('dAdvanced');
var lblHomework = document.getElementById('dHomework');
for (var i = 0; i < tiles.length; i++)
tiles[i].className = '';

domElement.classList.toggle('active');

lblTitle.innerHTML = title;

var id = titles.indexOf(title);
lblDescription.innerHTML = data[id][0];
lblConcepts.innerHTML = 'Concepts: ' + data[id][1];
lblChallenges.innerHTML = 'Challenges: ' + data[id][2];
lblAdvanced.innerHTML = 'Advanced: ' + data[id][3];
lblAdvanced.innerHTML = 'Homework: ' + data[id][4];
}

.tile-container {
width: 100%;
height: 100%;
display: flex;
}

.view-panel {
width: 30%;
box-shadow: 0px 5px 15px #111;
background-color: #fff;
color: #333;
padding: 5px;
}

.launch-button {
background-color: #fc0;
border-radius: 5px;
height: 50px;
width: 95%;
margin: auto;
cursor: wait;
transition: 0.5s all;
}

.launch-button:hover {
background-color: #da0;
}

.launch-button a {
text-decoration: none;
color: #333;
width: 100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
}

.tiles {
width: 70%;
display: flex;
align-items: flex-start;
justify-content: flex-start;
}

.tile-view {
list-style: none;
width: 100%;
display: flex;
flex-wrap: wrap;
align-items: flex-start;
justify-content: center;
padding: 0;
}

.tile-view li {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
will-change: all;
width: 150px;
height: 150px;
cursor: pointer;
transition: 0.5s background-color;
margin-left: 5px;
margin: 5px;
background-color: #222;
color: #eee;
box-shadow: 2px 2px 5px #111;
}

.tile-view li>a {
color: #eee;
text-decoration: none;
}

.tile-view li:hover {
background-color: #fc0;
box-shadow: 5px 5px 15px #111;
}

.tile-view li.active {
background-color: #fc0;
}

.tile-view li.active,
.tile-view li.active>a,
.tile-view li:hover,
.tile-view li:hover>a {
color: #333;
}

@media screen and (max-width: 750px) {
.view-panel {
display: none;
}
.tiles {
width: 100%;
}
.tile-view li {
width: 300px;
}
}

<div class="tile-container">
<div class="view-panel">
<h1 id="dTitle">Pong</h1>
<p id="dDescription">Pong is the equivalent of Hello World in the game development industry.</p>
<ul>
<li><span id="dConcepts">Concepts: Vectors, Rendering</span></li>
<li><span id="dChallenges">Challenges: Directions</span></li>
<li><span id="dAdvanced">Advanced: Adding obstacles.</span></li>
<li><span id="dHomework">Homework: Add effects.</span></li>
</ul>
<div class="launch-button"><a href="#">Launch</a></div>
</div>
<div class="tiles">
<ul class="tile-view">
<li onclick="swapGame(this, 'Pong')" class="active">
<i class="fas fa-gamepad" aria-hidden="true"></i>
<a href="#">Pong</a>
</li>
<li onclick="swapGame(this, 'Tetris')">
<i class="fas fa-gamepad" aria-hidden="true"></i>
<a href="#">Tetris</a>
</li>
<li onclick="swapGame(this, 'Pac-Man')">
<i class="fas fa-gamepad" aria-hidden="true"></i>
<a href="#">Pac-Man</a>
</li>
<li onclick="swapGame(this, 'Snake')">
<i class="fas fa-gamepad" aria-hidden="true"></i>
<a href="#">Snake</a>
</li>
<li onclick="swapGame(this, 'Super Mario')">
<i class="fas fa-gamepad" aria-hidden="true"></i>
<a href="#">Super Mario</a>
</li>
<li onclick="swapGame(this, 'Pokemon')">
<i class="fas fa-gamepad" aria-hidden="true"></i>
<a href="#">Pokemon</a>
</li>
<li onclick="swapGame(this, 'Match 3')">
<i class="fas fa-gamepad" aria-hidden="true"></i>
<a href="#">Match 3</a>
</li>
<li onclick="swapGame(this, 'Blossom Blast')">
<i class="fas fa-gamepad" aria-hidden="true"></i>
<a href="#">Blossom Blast</a>
</li>
<li onclick="swapGame(this, 'Driven')">
<i class="fas fa-gamepad" aria-hidden="true"></i>
<a href="#">Driven</a>
</li>
<li onclick="swapGame(this, 'Terrible Zombies')">
<i class="fas fa-gamepad" aria-hidden="true"></i>
<a href="#">Terrible Zombies</a>
</li>
</ul>
</div>
</div>






javascript dom






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 7 mins ago









200_success

129k15153415




129k15153415










asked 48 mins ago









PerpetualJPerpetualJ

1559




1559












  • $begingroup$
    Is there a reason why you want the text to be partly stored in the JavaScript code and partly in the HTML, rather than all in JavaScript or all in HTML?
    $endgroup$
    – 200_success
    5 mins ago


















  • $begingroup$
    Is there a reason why you want the text to be partly stored in the JavaScript code and partly in the HTML, rather than all in JavaScript or all in HTML?
    $endgroup$
    – 200_success
    5 mins ago
















$begingroup$
Is there a reason why you want the text to be partly stored in the JavaScript code and partly in the HTML, rather than all in JavaScript or all in HTML?
$endgroup$
– 200_success
5 mins ago




$begingroup$
Is there a reason why you want the text to be partly stored in the JavaScript code and partly in the HTML, rather than all in JavaScript or all in HTML?
$endgroup$
– 200_success
5 mins ago










0






active

oldest

votes











Your Answer





StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
});
});
}, "mathjax-editing");

StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "196"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f212183%2fchanging-the-text-of-a-few-elements-when-a-tile-is-clicked%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Code Review Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


Use MathJax to format equations. MathJax reference.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f212183%2fchanging-the-text-of-a-few-elements-when-a-tile-is-clicked%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Сан-Квентин

8-я гвардейская общевойсковая армия

Алькесар