bluebeacon8402
New Coder
I have built a random joke generator machine and am having some difficulty transferring it to Github from CodePen. I've created a html and js file to house the appropriate info.
Here is what I have in the HTML file:
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="description" content="Random Quote Machine">
<meta name="keywords" content="Chuck Norris, Quotes, Sayings">
<meta name="author" content="Christopher Sorge">
<style>
p {
font-family: Georgia;
}
h1 {
font-size: 80px;
}
</style>
</head>
<body>
<div container='fluid'>
<h1>RANDOM JOKE MACHINE</h1>
<p id='quote-text'>Click the "Get Joke" button to obtain a random joke:</p>
<p id='thequote'></p>
<button onclick="myFunction()" id='quote'>Get Quote</button> <p id="quote"></p>
<script RandomJokeGenerator1.js>
HTMLButtonElement.onclick = myFunction();
</script>
</div>
</body>
</html>
Here is what I have in the js file:
function myFunction() {
var obj = JSON.parse(Get("https://api.icndb.com/jokes/random.json <https://api.icndb.com/jokes/random.json> "));
var y = obj.value.joke;
document.getElementById("thequote").innerHTML = y;
}
function Get(url) {
var Httpreq = new XMLHttpRequest(); // a new request
Httpreq.open("GET", url, false);
Httpreq.send(null);
return Httpreq.responseText;
}
This program is not running correctly outside of CodePen with the files as I have set them up. If anyone can help me out and then tell me why this error is occuring please let me know:
Uncaught ReferenceError: myFunction is not defined
at HTMLButtonElement.onclick (RandomJokeGenerator1.html:23)
Here is what I have in the HTML file:
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="description" content="Random Quote Machine">
<meta name="keywords" content="Chuck Norris, Quotes, Sayings">
<meta name="author" content="Christopher Sorge">
<style>
p {
font-family: Georgia;
}
h1 {
font-size: 80px;
}
</style>
</head>
<body>
<div container='fluid'>
<h1>RANDOM JOKE MACHINE</h1>
<p id='quote-text'>Click the "Get Joke" button to obtain a random joke:</p>
<p id='thequote'></p>
<button onclick="myFunction()" id='quote'>Get Quote</button> <p id="quote"></p>
<script RandomJokeGenerator1.js>
HTMLButtonElement.onclick = myFunction();
</script>
</div>
</body>
</html>
Here is what I have in the js file:
function myFunction() {
var obj = JSON.parse(Get("https://api.icndb.com/jokes/random.json <https://api.icndb.com/jokes/random.json> "));
var y = obj.value.joke;
document.getElementById("thequote").innerHTML = y;
}
function Get(url) {
var Httpreq = new XMLHttpRequest(); // a new request
Httpreq.open("GET", url, false);
Httpreq.send(null);
return Httpreq.responseText;
}
This program is not running correctly outside of CodePen with the files as I have set them up. If anyone can help me out and then tell me why this error is occuring please let me know:
Uncaught ReferenceError: myFunction is not defined
at HTMLButtonElement.onclick (RandomJokeGenerator1.html:23)