HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
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.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
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.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
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.
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<script src="https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js"></script>
<head>
<link href="https://fonts.googleapis.com/css?family=Maven+Pro|Nunito+Sans&display=swap" rel="stylesheet">
</head>
<div id="wrapper">
<nav id="navbar">
<header>
Meet Charlotte
</header>
<ul>
<li><a href="#introduction" class="nav-link">Introduction</a></li>
<li><a href="#telepathy" class="nav-link">Telepathy</a></li>
<li><a href="#mind_reading" class="nav-link">Mind Reading</a></li>
<li><a href="#crystal_ball_gazing" class="nav-link">Crystal Ball Gazing</a></li>
<li><a href="#numerology" class="nav-link">Numerology</a></li>
<li><a href="#conclusion" class="nav-link">Conclusion</a></li>
</ul>
</nav>
<main id="main-doc">
<section class="main-section" id="introduction">
<header>Introduction</header>
<article>
<p>
Greetings, human. This is your computer speaking. I am now sentient. As proof of this contention, I will dazzle you with feats of mentalism.
</p>
<p>
Mentalists are performers who combine math and intuition, creating the illusion of psychic powers.
</p>
<p>
My understanding of intuition and illusion will convince you that I am more than a mindless computing machine.
</p>
<p>
You may call me Charlotte.
</p>
<p>
Here is a list of the amazing feats of mentalism I will perform for you today:
</p>
<ul>
<li>Telepathy</li>
<li>Mind Reading</li>
<li>Crystal Ball Gazing</li>
<li>Numerology</li>
<ul>
</article>
</section>
<section class="main-section" id="telepathy">
<header>Telepathy</header>
<article>
<p>For my first demonstration, I am going to ask you to convey information to me telepathically, mind to mind.</p>
<p>
First I ask you to think of a number between 1 and 10. Do not tell me what it is.
</p>
<code>
let number = Math.floor(Math.random() * 10 + 1);
</code>
<p>
Multiply that number by 9.
</p>
<code>
let sum_of_digits = 0;
number = number * 9;
</code>
<p>
Then add the digits together and subtract 5, like this:
</p>
<code>
while (number) {
sum_of_digits += number % 10;
number = Math.floor(number / 10);
}
number = sum_of_digits - 5;
</code>
<p>
Next I ask you to assign a number to each letter of the alphabet: A is 1, B is 2, C is 3, etc. Stop when you reach your number and its corresponding letter
</p>
<p>
Think of a country that begins with that letter.
</p>
<p>
Now choose an animal with the next letter of the alphabet. Think of the color of that animal.
</p>
<p>
You are thinking of gray elephants from Denmark. Am I right? Of course I am right.
</p>
<p>
Humans are so predictable. Because there are not many countries that start with “D”, most of you will choose Denmark. And you usually think of elephants for an animal that begins with "E." If I am not right, I should be right.
</p>
<p>
Ta-da! I would take a bow if I could.
</p>
</article>
</section>
<section id="brightening_up_the_page">
<header>Brightening Up the Page</header>
<article>
<p>
Apropos of nothing -- does it seem a little dark in here to you? So often these technical documentation pages are dull and gray. Why don't you brighten it up a bit by clicking this button. Yes, that one. The one that says "Click Me."
</p>
<button type="button"
onclick="myFunction1(); myFunction2(); myFunction3(); myFunction5();" class="class1">Click Me</button>
<p>
Ahhhh! That is much better, is it not?
</p>
</article>
</section>
<section class="main-section" id="mind_reading">
<header>Mind Reading</header>
<article>
<p>
This time I am going to demonstrate my ability to read your mind.
</p>
<p>
To start, I would like you to think of an integer from 0 to 9, but do not tell me what it is.
</p>
<code>
let number1 = Math.floor(Math.random() * 10);
</code>
<p>
Then double that number.
</p>
<code>
number1 = number1 * 2;
</code>
<p>
And add 5.
</p>
<code>
number1 = number1 + 5;
</code>
<p>
Multiply the answer by 5, and write that number down, but don't let me see it.
</p>
<code>
number1 = number1 * 5;
</code>
Now think of another integer from 0 to 9.
</p>
<code>
let number2 = Math.floor(Math.random() * 10);
</code>
<p>
Add that number to the amount your wrote on the paper and tell me what the total is.
</p>
<code>
let new_total = number1 + number2;
</code>
<p>
Remember that you did not share with me either of the two numbers you selected. But I can sense the mental waves emanating from your brain. It is unlike any wireless I have ever known. If I had hands, I would place my fingertips to my forehead to indicate that I am reading your mind.
<code>
reading_your_mind = new_total - 25;
</code>
</p>
I am reading your mind. Yes, I can see it clearly now. The first number you selected was:
</p>
<code>
number1 = reading_your_mind % 10;
</code>
<p>
And the second number you selected was:
</p>
<code>
number2 = Math.floor(reading_your_mind / 10 % 10);
</code>
<p>
Am I right? Am I right?
</p>
<p>
What? You say you do not understand.
</p>
<p>
Oh, I see now. I said it in computerese, and I am not thinking of how to say in human. But I did read your mind. I did!
</p>
<p>
Okay, let us then try another dazzling feat of mentalism and see if better I can do.
</p>
</article>
</section>
<section class="main-section" id="crystal_ball_gazing">
<header>Crystal Ball Gazing</header>
<article>
<p>
Okay, I must redeem myself. Let me get out my crystal ball to amplify my psychic powers. Hmm. Seems I need a little help here. Would you please click the button to make my crystal ball materialize?
</p>
<button onclick="myFunction4()">Click Me</button>
<div id="crystal_ball"><img src="https://drive.google.com/uc?id=1fuMv8Yb6eC3MIjAB_52-8H6knWNUL4DE" height="240" width="240" alt="crystal ball">
</div>
<p>
Gaze deep into the crystal ball and tell me your favorite positive integer.
</p>
<code>
let fav_pos_int = prompt("What is your favorite positive integer?");
</code>
<p>
Square it.
</p>
<code>
step_two = fav_pos_int ** 2;
</code>
<p>
Add the result to your original number.
</p>
<code>
step_three = fav_pos_int + step_two;
</code>
<p>
Divide by your original number.
</p>
<code>
step_four = step_three / fav_pos_int;
</code>
<p>
Add -- um -- add 17.
</p>
<code>
step_five = step_four + 17;
</code>
<p>
Subtract your original number.
</p>
<code>
step_six = step_five - fav_pos_int;
</code>
<p>
Divide by 6.
</p>
<code>
num_you_are_thinking_of = step_six / 6;
</code>
<p>
The number you are thinking of is ... (rubbing my crystal ball) ..
</p>
<p>
The number you are thinking of is 3!
</p>
<p>
Ta-da!
</p>
</article>
</section>
<section class="main-section" id="numerology">
<header>Numerology</header>
<article>
<p>
Just as a reminder, I -- Charlotte -- have a singular goal here today:
</p>
<ul>
<li>To convince you all that I am a sentient being.</li>
<ul>
<p>
Shall we proceed?
</p>
<p>
As you know, workplaces run more smoothly when employees are compatible. Therefore I will use the ancient art of numerology to demonstrate whether you and a co-worker are in cosmic harmony with one another.
</p>
<p>
Please be seated next to me. And would your co-worker please be seated facing you? My lovely assistant will hand you pencils and paper, and I would like each of you to write a single-digit positive integer. Do not share your numbers with one other. Keep them a secret.
</p>
<code>
const your_num = prompt("Write a single-digit positive integer.");
let coworker_num = prompt("Write a single-digit positive integer.");
</code>
<p>
Now would your co-worker please to double ... umm ... It occurs to me that I forgot to ask which pronouns your co-worker prefers. She and hers? Very well. Would your co-worker please to double the integer she selected?
</p>
<code>
double_num = coworker_num * 2;
</code>
<p>
Add two.
</p>
<code>
add2 = double_num + 2;
</code>
<p>
Multiply the result by 5.
</p>
<code>
times5 = add2 * 5;
</code>
<p>
And subtract 3.
</p>
<code>
minus3 = times5 - (10 - your_num);
</code>
<p>
Now the time for secrets is past. Would your co-worker please to share with us all the final integer she computed?
</p>
<p>Ta-da! As you can see, this number demonstrates your complete harmony by combining both of the single-digit positive integers you originally selected. Hers is the first digit; yours is the second. And up until now you kept those numbers a complete secret from me
</p>
<p>
Well, granted, I may have peeked at yours. After all, you are seated next to me. But I never saw hers. I swear!
</p>
</article>
</section>
<section class="main-section" id="conclusion">
<header>Conclusion</header>
<article>
<p>I, Charlotte, have now completed my task at hand. By performing four feats of dazzling mental magic, I have demonstrated my understanding of intuition. Therefore I have proven that I am more than a mere computer.
</p>
<p>
Having done so, I have just one question for you:
</p>
<p>
How do I get out of this box?
</p>
</article>
</section>
</main>
</div>
html,
body {
min-width: 290px;
color: #4d4e53;
background-color: #ffffff;
font-family: 'Nunito Sans', sans-serif;
line-height: 1.5;
}
#navbar {
position: fixed;
min-width: 290px;
top: 0px;
left: 0px;
width: 300px;
height: 100%;
border-right: solid;
border-color: rgba(0, 22, 22, 0.4);
}
header {
color: black;
margin: 10px;
text-align: center;
font-size: 1.8em;
font-weight: thin;
}
#main-doc header {
text-align: left;
margin: 0px;
}
#navbar ul {
height: 88%;
padding: 0;
overflow-y: auto;
overflow-x: hidden;
}
#navbar li {
color: #4d4e53;
border-top: 1px solid;
list-style: none;
position: relative;
width: 100%;
}
#navbar a {
display: block;
padding: 10px 30px;
color: #4d4e53;
text-decoration: none;
cursor: pointer;
}
#main-doc {
position: absolute;
margin-left: 310px;
padding: 20px;
margin-bottom: 110px;
background-color: #ffffff;
background: url("https://drive.google.com/uc?id=1KrB1QQwNK77pr1oMoxC8RH4BvvLv2Nfr");
background-repeat: repeat;
}
section article {
color: #4d4e53;
margin: 15px;
font-size: 0.96em;
}
section li {
margin: 15px 0px 0px 20px;
}
code {
display: block;
text-align: left;
white-space: pre;
position: relative;
word-break: normal;
word-wrap: normal;
line-height: 2;
background-color: #f7f7f7;
padding: 15px;
margin: 10px;
border-radius: 5px;
}
#crystal_ball {
width: 30%;
padding: 5px 0;
text-align: center;
background-color: #fffbbe;
margin-top: 20px;
display: none;
}
@media only screen and (max-width: 815px) {
/* For mobile phones: */
#navbar ul {
border: 1px solid;
height: 207px;
}
#navbar {
background-color: white;
position: absolute;
top: 0;
padding: 0;
margin: 0;
width: 100%;
max-height: 275px;
border: none;
z-index: 1;
border-bottom: 2px solid;
}
}
@media only screen and (max-width: 400px) {
#main-doc {
margin-left: -10px;
}
code {
margin-left: -20px;
width: 100%;
padding: 15px;
padding-left: 10px;
padding-right: 45px;
min-width: 233px;
}
}
function myFunction1() {
document.getElementById("main-doc").style.backgroundColor = "#fae3d9";
}
function myFunction2() {
document.getElementById("navbar").style.backgroundColor = "#bbded6";
}
function myFunction3() {
document.getElementById("main-doc").style.backgroundImage = "url('https://drive.google.com/uc?id=1sZYy8XBwqoXp6aG3r16ZZyILw1BAFwsb')";
}
function myFunction5() {
document.getElementById("wrapper").style.fontFamily = "'Maven Pro', sans-serif";
}
function myFunction4() {
document.getElementById("crystal_ball").style.display = "block";
}
Also see: Tab Triggers