I am trying to finish the Twitch TV challenge, and am stuck in being unable to fulfill one of the user stories, that being:
“I can click the status output and be sent directly to the Free Code Camp’s Twitch.tv channel.”
Instead, when I click on the button, a new window opens but fails to load the Twitch TV channel page even though the correct URL is shown at the top of the new window.
I tried to get something from the browser console (Cntrl-shift-J), but it seems that nothing is being displayed when the new window opens even though the correct URL is shown at the top.
target="_blank" has been included
The link to my CodePen is:
https://codepen.io/smithfred0987/pen/BxrVNX
My HTML code is:
<div class="container-fluid">
<div class = "row text-center">
<h2>Twitch App</h2>
</div>
</div>
<div class="card border-secondary" style="width: 18rem;">
<img class="card-img-top" id="imofcard0" src="https://images.freeimages.com/images/small-previews/615/corcovado-sunset-1527899.jpg" alt="Card image">
<div class="card-body">
<h2 class="card-title" id="result0title">Card title 0</h2>
<p class="card-text" id="result0text">card text 0</p>
<a href="#" class="btn btn-primary" target = "_blank" id="result0link">Go to Twitch TV Channel!</a>
</div>
</div>
<br><br>
<div class="card border-secondary" style="width: 18rem;">
<img class="card-img-top" id="imofcard1" src="https://images.freeimages.com/images/small-previews/615/corcovado-sunset-1527899.jpg" alt="Card image">
<div class="card-body">
<h2 class="card-title" id="result1title">Card title 1</h2>
<p class="card-text" id="result1text">card text 1</p>
<a href="#" class="btn btn-primary" target = "_blank" id="result1link">Go to Twitch TV Channel!</a>
</div>
</div>
<br><br>
<div class="card border-secondary" style="width: 18rem;">
<img class="card-img-top" id="imofcard2" src="https://images.freeimages.com/images/small-previews/615/corcovado-sunset-1527899.jpg" alt="Card image">
<div class="card-body">
<h2 class="card-title" id="result2title">Card title 2</h2>
<p class="card-text" id="result2text">card text 2</p>
<a href="#" class="btn btn-primary" target = "_blank" id="result2link">Go to Twitch TV Channel!</a>
</div>
</div>
<br><br>
<div class="card border-secondary" style="width: 18rem;">
<img class="card-img-top" id="imofcard3" src="https://images.freeimages.com/images/small-previews/615/corcovado-sunset-1527899.jpg" alt="Card image">
<div class="card-body">
<h2 class="card-title" id="result3title">Card title 3</h2>
<p class="card-text" id="result3text">card text 3</p>
<a href="#" class="btn btn-primary" target = "_blank" id="result3link">Go to Twitch TV Channel!</a>
</div>
</div>
<br><br>
<div class="card border-secondary" style="width: 18rem;">
<img class="card-img-top" id="imofcard4" src="https://images.freeimages.com/images/small-previews/615/corcovado-sunset-1527899.jpg" alt="Card image">
<div class="card-body">
<h2 class="card-title" id="result4title">Card title 4</h2>
<p class="card-text" id="result4text">card text 4</p>
<a href="#" class="btn btn-primary" target = "_blank" id="result4link">Go to Twitch TV Channel!</a>
</div>
</div>
<br><br>
<div class="card border-secondary" style="width: 18rem;">
<img class="card-img-top" id="imofcard5" src="https://images.freeimages.com/images/small-previews/615/corcovado-sunset-1527899.jpg" alt="Card image">
<div class="card-body">
<h2 class="card-title" id="result5title">Card title 5</h2>
<p class="card-text" id="result5text">card text 5</p>
<a href="#" class="btn btn-primary" target = "_blank" id="result5link">Go to Twitch TV Channel!</a>
</div>
</div>
<br><br>
<div class="card border-secondary" style="width: 18rem;">
<img class="card-img-top" id="imofcard6" src="https://images.freeimages.com/images/small-previews/615/corcovado-sunset-1527899.jpg" alt="Card image">
<div class="card-body">
<h2 class="card-title" id="result6title">Card title 6</h2>
<p class="card-text" id="result6text">card text 6</p>
<a href="#" class="btn btn-primary" target = "_blank" id="result6link">Go to Twitch TV Channel!</a>
</div>
</div>
<br><br>
<div class="card border-secondary" style="width: 18rem;">
<img class="card-img-top" id="imofcard7" src="https://images.freeimages.com/images/small-previews/615/corcovado-sunset-1527899.jpg" alt="Card image">
<div class="card-body">
<h2 class="card-title" id="result7title">Card title 7</h2>
<p class="card-text" id="result7text">card text 7</p>
<a href="#" class="btn btn-primary" target = "_blank" id="result7link">Go to Twitch TV Channel!</a>
</div>
</div>
<br><br>
<div class="card border-secondary" style="width: 18rem;">
<img class="card-img-top" id="imofcard8" src="https://images.freeimages.com/images/small-previews/615/corcovado-sunset-1527899.jpg" alt="Card image">
<div class="card-body">
<h2 class="card-title" id="result8title">Card title 8</h2>
<p class="card-text" id="result8text">card text 8</p>
<a href="#" class="btn btn-primary" target = "_blank" id="result8link">Go to Twitch TV Channel!</a>
</div>
</div>
and my Javascript code is:
var channarr = ["MedryBW", "ESL_SC2", "OgamingSC2", "cretetion", "freecodecamp", "storbeck", "habathcx", "RobotCaleb", "noobs2ninjas"];
$(document).ready(function() {
for (let i = 0; i < channarr.length; i++) {
console.log("the value of channarr[", i, "] is: ", channarr[i]);
$.ajax({
type: "GET",
cache: false,
dataType: 'json',
url: "https://wind-bow.gomix.me/twitch-api/channels/" + channarr[i] + "?callback=?",
data: "json",
async: false,
success: processResults,
});
function processResults(json) {
$.ajax({
type: "GET",
dataType: 'json',
url: "https://wind-bow.gomix.me/twitch-api/streams/" + channarr[i] + "?callback=?",
data: "isitlive",
success: arelive,
});
function arelive(isitlive){
if (isitlive.stream == null) {
console.log("this stream is currently offline");
document.getElementById("result" + i + "text").innerHTML="Now Offline";
}
else {
console.log("this stream is currently streaming");
document.getElementById("result" + i + "text").innerHTML=json.status;
}
console.log("the x value of channarr[", i, "] is: ", channarr[i]);
console.log("the display name is: ", json.display_name);
console.log("the game is: ", json.game);
console.log("the logo link is: ", json.logo);
console.log("the Twitch TV link is: ", json.url);
document.getElementById("result" + i + "title").innerHTML=json.display_name;
document.getElementById("imofcard" + i).src=json.logo;
document.getElementById("result" + i + "link").href=json.url;
};
};
}});