You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
1005 B
37 lines
1005 B
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
|
<title>Document</title>
|
|
</head>
|
|
<body>
|
|
<div style="text-align: center; font-size: 50px ;">
|
|
<button onclick="getRandomJoke()">Get Joke</button>
|
|
<h2 id="jokearea" ></h2>
|
|
</div>
|
|
|
|
<script>
|
|
var jokejson;
|
|
var jokearea = document.getElementById("jokearea");
|
|
|
|
function getRandomJoke(){
|
|
const ajax = new XMLHttpRequest;
|
|
const url = "https://api.chucknorris.io/jokes/random";
|
|
ajax.open("GET", url, true);
|
|
ajax.onreadystatechange = function() {
|
|
if(this.status === 200 && this.readyState === 4){
|
|
console.log(this.responseText);
|
|
jokejson = JSON.parse(this.responseText);
|
|
jokearea.innerHTML = jokejson["value"];
|
|
} else {
|
|
jokearea.innerHTML ="error"
|
|
}
|
|
}
|
|
ajax.send();
|
|
}
|
|
|
|
</script>
|
|
</body>
|
|
</html>
|