Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • 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.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • 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)
 

New Threads

Latest posts

Buy us a coffee!

Back
Top Bottom