Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <html lang="en">
	<head>
		<meta charset="UTF-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=edge" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<link rel="preconnect" href="https://fonts.googleapis.com" />
		<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
		<link
			href="https://fonts.googleapis.com/css2?family=Berkshire+Swash&display=swap"
			rel="stylesheet"
		/>
		<link rel="stylesheet" href="styles.css" />
		<script src="main.js" defer></script>
		<title>Chuck Norris Valentine's Day card 1</title>
	</head>
	<body>
		<div id="container">
			<button onclick="fetchJoke()">Get a new random joke! 💘</button>
			<h3 id="title">Happy Valentine's Day from Chuck Norris!</h3>
			<div class="card">
				<img
					src="https://upload.wikimedia.org/wikipedia/commons/thumb/b/b1/Chuck_Norris%2C_The_Delta_Force_1986.jpg/330px-Chuck_Norris%2C_The_Delta_Force_1986.jpg"
					alt="Avatar"
					style="width: 100%"
				/>
			</div>
			<p id="display-joke"
				>A Chuck Norris movie will touch your heart. Then it will rip it out of
				your chest!</p
			> </div
		><!-- container -->
	</body>
</html>
              
            
!

CSS

              
                body {
	color: white;
	font-family: "Berkshire Swash", cursive;
}

button {
	background-color: pink;
	border-radius: 25px;
}

button:hover {
	background-color: white;
	cursor: pointer;
}

img {
	max-width: 150px;
	border: 3px dotted darkred;
}

#container {
	width: 300px;
	text-align: center;
	margin: 0 auto;
	padding: 25px;
	background: url("https://cdn.pixabay.com/photo/2018/01/18/02/20/heart-3089409_960_720.jpg");
	background-repeat: no-repeat;
	box-shadow: 10px 10px 10px rgba(0, 0, 0, 0.5);
}

#title {
	text-shadow: -1px -1px 3px red, 1px 2px 1px black;
	padding: 5px;
	width: 100%;
}

#display-joke {
	background: rgba(0, 0, 0, 0.8);
	background-color: whitesmoke;
	color: black;
	text-shadow: 1px 1px 1px rgba(255, 0, 0, 0.9);
	padding: 25px;
}
              
            
!

JS

              
                console.clear();

const displayJoke = document.getElementById("display-joke");

async function fetchJoke() {
const errorMessage = `"DO NOT DISTURB!" Chuck Norris is currently entertaining guests in his hotel room.`;
  
	try {
		const results = await fetch(`https://api.chucknorris.io/jokes/random`);
  
		if (!results.ok) {
      displayJoke.textContent = errorMessage;
			throw new Error("Request failed.");
		}    
    
		const data = await results.json();
    displayJoke.textContent = data.value;
      console.log(data.value);
	} catch (error) {
    displayJoke.textContent = errorMessage;
		console.error(error);
	}
}
fetchJoke();
              
            
!
999px

Console