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.
<!--
Hello Camper!
Please read the README below in the JS Editor before beginning. Feel free to delete this message once you have read it. Good luck and Happy Coding!
- The freeCodeCamp Team
-->
<nav id="navbar">
<header>
<h1>JavaScript Documentation</h1>
</header>
<section>
<a href="#Introduction" class="nav-link">Introduction</a>
<a href="#JavaScript_and_Java" class="nav-link">JavaScript and Java</a>
<a href="#Hello_world" class="nav-link">Hello world</a>
<a href="#Data_types" class="nav-link">Data types</a>
<a href="#if-else_statement" class="nav-link">if-else statement</a>
<a href="#Function_declarations" class="nav-link">Function declarations</a>
</section>
</nav>
<main id="main-doc">
<section class="main-section" id="Introduction">
<header>Introduction</header>
<p>
JavaScript is a cross-platform, object-oriented scripting language. It is a small and lightweight
language. Inside a host environment (for example, a web browser), JavaScript can be connected to the
objects of its environment to provide programmatic control over them.
</p>
<p>
JavaScript contains a standard library of objects, such as Array, Date, and Math, and a core set of
language elements such as operators, control structures, and statements. Core JavaScript can be extended
for a variety of purposes by supplementing it with additional objects; for example:
</p>
<ul>
<li>
Client-side JavaScript extends the core language by supplying objects to control a browser and its
Document Object Model (DOM). For example, client-side extensions allow an application to place
elements on an HTML form and respond to user events such as mouse clicks, form input, and page
navigation.
</li>
<li>
Server-side JavaScript extends the core language by supplying objects relevant to running JavaScript
on a server. For example, server-side extensions allow an application to communicate with a
database, provide continuity of information from one invocation to another of the application, or
perform file manipulations on a server.
</li>
</ul>
</section>
<section class="main-section" id="JavaScript_and_Java">
<header>JavaScript and Java</header>
<p>
Server-side JavaScript extends the core language by supplying objects relevant to running JavaScript on
a server. For example, server-side extensions allow an application to communicate with a database,
provide continuity of information from one invocation to another of the application, or perform file
manipulations on a server.
</p>
<p>
In contrast to Java's compile-time system of classes built by declarations, JavaScript supports a
runtime system based on a small number of data types representing numeric, Boolean, and string values.
JavaScript has a prototype-based object model instead of the more common class-based object model. The
prototype-based model provides dynamic inheritance; that is, what is inherited can vary for individual
objects. JavaScript also supports functions without any special declarative requirements. Functions can
be properties of objects, executing as loosely typed methods.
</p>
<p>
JavaScript is a very free-form language compared to Java. You do not have to declare all variables,
classes, and methods. You do not have to be concerned with whether methods are public, private, or
protected, and you do not have to implement interfaces. Variables, parameters, and function return types
are not explicitly typed.
</p>
</section>
<section class="main-section" id="Hello_world">
<header>Hello world</header>
<p>
To get started with writing JavaScript, open the Scratchpad and write your first "Hello world"
JavaScript code:
</p>
<code>
<pre>function greetMe(yourName) { alert("Hello " + yourName); }
greetMe("World");</pre>
</code>
<p>
Select the code in the pad and hit Ctrl+R to watch it unfold in your browser!
</p>
</section>
<section class="main-section" id="Data_types">
<header>Data types</header>
<p>The latest ECMAScript standard defines seven data types:</p>
<ul>
<li>
Six data types that are primitives:
<ul>
<li>
Boolean. true and false.
</li>
<li>
null. A special keyword denoting a null value. Because JavaScript is case-sensitive, null is
not the same as Null, NULL, or any other variant.
</li>
<li>
undefined. A top-level property whose value is undefined.
</li>
<li>
Number. 42 or 3.14159.
</li>
<li>
String. "Howdy"
</li>
<li>
Symbol (new in ECMAScript 2015). A data type whose instances are unique and immutable.
</li>
</ul>
</li>
<li>and Object</li>
</ul>
<p>
Although these data types are a relatively small amount, they enable you to perform useful functions
with your applications. Objects and functions are the other fundamental elements in the language. You
can think of objects as named containers for values, and functions as procedures that your application
can perform.
</p>
</section>
<section class="main-section" id="if-else_statement">
<header>if-else statement</header>
<p>
Use the if statement to execute a statement if a logical condition is true. Use the optional else clause
to execute a statement if the condition is false. An if statement looks as follows:
</p>
<code>
<pre>if (condition) { statement_1; } else { statement_2; }</pre>
</code>
<p>
condition can be any expression that evaluates to true or false. See Boolean for an explanation of what
evaluates to true and false. If condition evaluates to true, statement_1 is executed; otherwise,
statement_2 is executed. statement_1 and statement_2 can be any statement, including further nested if
statements.
</p>
<p>
You may also compound the statements using else if to have multiple conditions tested in sequence, as
follows:
</p>
<code>
<pre>if (condition_1) { statement_1; } else if (condition_2) { statement_2;
} else if (condition_n) { statement_n; } else { statement_last; }</pre>
</code>
<p>
In the case of multiple conditions only the first logical condition which evaluates to true will be
executed. To execute multiple statements, group them within a block statement ({ ... }) . In general,
it's good practice to always use block statements, especially when nesting if statements:
</p>
<code>
<pre>if (condition) { statement_1_runs_if_condition_is_true;
statement_2_runs_if_condition_is_true; } else {
statement_3_runs_if_condition_is_false;
statement_4_runs_if_condition_is_false; }</pre>
</code>
<p>
It is advisable to not use simple assignments in a conditional expression, because the assignment can be
confused with equality when glancing over the code. For example, do not use the following code:
</p>
<code>
<pre>if (x = y) { /* statements here */ }</pre>
</code>
<p>
If you need to use an assignment in a conditional expression, a common practice is to put additional
parentheses around the assignment. For example:
</p>
<code>
<pre>if ((x = y)) { /* statements here */ }</pre>
</code>
</section>
<section class="main-section" id="Function_declarations">
<header>Function declarations</header>
<p>A function definition (also called a function declaration, or function statement) consists of the
function keyword, followed by:</p>
<ul>
<li>The name of the function.</li>
<li>A list of arguments to the function, enclosed in parentheses and separated by commas.</li>
<li>The JavaScript statements that define the function, enclosed in curly brackets, { }.</li>
</ul>
<p>For example, the following code defines a simple function named square:</p>
<code>
<pre>function square(number) { return number * number; }</pre>
</code>
<p>
The function square takes one argument, called number. The function consists of one statement that says
to return the argument of the function (that is, number) multiplied by itself. The return statement
specifies the value returned by the function.
</p>
<code>
<pre>return number * number;</pre>
</code>
<p>
Primitive parameters (such as a number) are passed to functions by value; the value is passed to the
function, but if the function changes the value of the parameter, this change is not reflected globally
or in the calling function.
</p>
</section>
</main>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
ul li {
padding: 5px;
margin-left: 30px;
}
p {
margin: 10px 0;
margin-left: 10px;
}
pre {
white-space: pre-wrap;
word-wrap: break-word;
}
body {
display: flex;
overflow-y: hidden;
}
nav {
display: flex;
flex-direction: column;
padding: 15px 0;
height: 100vh;
border-right: black solid 2px;
overflow-y: auto;
height: 100vh;
min-width: 200px;
}
nav section {
overflow-y: auto;
margin-top: 10px;
}
nav header {
display: block;
margin-left: 20px;
}
nav a {
display: block;
padding: 10px 20px;
border-top: rgb(110, 110, 110) solid 1px;
color: black;
text-decoration: none;
font-size: 1.1em;
transition: 0.3s;
}
nav a:hover {
color: red;
text-decoration: underline;
margin-left: 5px;
}
main {
padding: 15px;
overflow-y: scroll;
height: 100vh;
padding-bottom: 30px;
}
main>* {
margin-bottom: 20px;
}
main section>header {
font-size: 1.7em;
font-weight: bold;
margin-bottom: 10px;
}
main section code>pre {
background-color: rgb(235, 235, 235);
padding: 15px 30px;
margin-left: 10px;
}
@media screen and (max-width: 750px) {
body {
flex-direction: column;
overflow-y: scroll;
}
nav {
height: auto;
border-right: none;
}
nav section {
height: 150px;
overflow-y: scroll;
margin-top: 10px;
border: black solid 2px;
}
main {
height: auto;
overflow-y: unset;
}
}
// !! IMPORTANT README:
// You may add additional external JS and CSS as needed to complete the project, however the current external resource MUST remain in place for the tests to work. BABEL must also be left in place.
/***********
INSTRUCTIONS:
- Select the project you would
like to complete from the dropdown
menu.
- Click the "RUN TESTS" button to
run the tests against the blank
pen.
- Click the "TESTS" button to see
the individual test cases.
(should all be failing at first)
- Start coding! As you fulfill each
test case, you will see them go
from red to green.
- As you start to build out your
project, when tests are failing,
you should get helpful errors
along the way!
************/
// PLEASE NOTE: Adding global style rules using the * selector, or by adding rules to body {..} or html {..}, or to all elements within body or html, i.e. h1 {..}, has the potential to pollute the test suite's CSS. Try adding: * { color: red }, for a quick example!
// Once you have read the above messages, you can delete all comments.
Also see: Tab Triggers