• Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.
    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

JavaScript Issue running into getting this app to run

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)
 

Malcolm

Administrator
Administrator
Verified
Hello,

Welcome to Code Forum! Glad you figured this out, by invoking the src what do you mean by that?

And also when posting code please use our BBCode. Read more here.
 
Top Bottom