<div class="main">
<h1>↯ Click Me ↯</h1>
<img id="logo" src="https://www.sccpre.cat/mypng/detail/130-1307426_chuck-norris-by-chuck-norris-illustration.png" />
<div id="data"></div>
</div>
body { background-color: #F0F4F8; color: #243B53;
font: normal 100% Cambria, Georgia, serif; }
.main {
background-color: #ffffff;
margin: 0 auto;
max-width: 640px;
border: 5px solid #102A43;
margin-top: 8.666666%;
padding: 3.666666%;
text-align: center;
box-shadow: 0 1px 1px rgba(0,0,0,0.11),
0 2px 2px rgba(0,0,0,0.11),
0 4px 4px rgba(0,0,0,0.11),
0 8px 8px rgba(0,0,0,0.11),
0 16px 16px rgba(0,0,0,0.11),
0 32px 32px rgba(0,0,0,0.11);
}
#data {
width: 93.75%;
border-left: 1px dashed black;
text-align: center;
}
#logo {
width: 50%;
height: auto;
margin: 0 auto;
margin-top: 8.666666%;
margin-bottom: 4.333333%;
display: block;
}
/* Box sizing rules */
*,
*::before,
*::after {
box-sizing: border-box;
}
/* Remove default padding */
ul[class],
ol[class] {
padding: 0;
}
/* Remove default margin */
body,
h1,
h2,
h3,
h4,
p,
ul[class],
ol[class],
li,
figure,
figcaption,
blockquote,
dl,
dd {
margin: 0;
}
/* Set core body defaults */
body {
max-height: 100vh;
scroll-behavior: smooth;
text-rendering: optimizeSpeed;
line-height: 1.5;
}
/* Remove list styles on ul, ol elements with a class attribute */
ul[class],
ol[class] {
list-style: none;
}
/* A elements that don't have a class get default styles */
a:not([class]) {
text-decoration-skip-ink: auto;
}
/* Make images easier to work with */
img {
max-width: 100%;
display: block;
}
/* Natural flow and rhythm in articles by default */
article > * + * {
margin-top: 1em;
}
/* Inherit fonts for inputs and buttons */
input,
button,
textarea,
select {
font: inherit;
}
/* Remove _all_ animations and transitions for people that prefer not to see them */
@media (prefers-reduced-motion: reduce) {
* {
animation-play-state: paused !important;
transition: none !important;
scroll-behavior: auto !important;
}
}
@media screen and (min-width: 320px) {
html {
font-size: calc(16px + 6 * ((100vw - 320px) / 680));
}
}
@media screen and (min-width: 1000px) {
html {
font-size: 22px;
}
}
document.addEventListener('DOMContentLoaded', () => {
function randomFact () {
// Call the web service via AJAX
var xhr = new XMLHttpRequest();
var url = 'https://api.chucknorris.io/jokes/random';
xhr.onreadystatechange = function () {
if (this.readyState === 4 && this.status === 200) {
var json = JSON.parse(this.responseText);
// parse the json response
parseJson(json);
}
};
xhr.open('GET', url, true);
xhr.send();
}
function parseJson(json) {
// display the value property of the JSON Object returned
var fact = "<b>" + "❝ " + json['value'] + " ❞" + "</b>";
document.getElementById('data').innerHTML = fact;
}
document.getElementById('logo').addEventListener('click', function () {
randomFact();
}, false);
randomFact();
}, false);
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.