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.

!
##### Insecure Resource

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.

+ add another resource

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.

+ add another resource

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.

` ````
```

` ````
```

` ````
///////////////////////////////// Math Methods ////////////////////////////////
// The JavaScript Math object has a lot of useful methods that are worth mentioning.
// To use the Math methods, we don't have to construct a new Math object.
// All we do is include the Math object name, and then invoke the method, such as:
let roundUp = Math.round(9.8); // here we invoked the round method. This would round 9.8 to 10.
// There are a few constants loaded into the JS Math object's properties.
// A few of these include:
// 1. PI : Math.PI
// 2. Euler's constant : Math.E
// 3. Natural log base 10: Math.LN10
// More : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math
// The Math object also has many methods, but we will only cover the ones you will likely use most
// If you'd like to see a full list of the Math object's methods, go to https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math
// 1. Exponents:
// Syntax: Math.pow(x,y) where x is the base and y is the exponent
// Examples:
let value = Math.pow(5, 2);
let newValue = Math.pow(value, 2);
// 2. Random:
// Syntax: Math.random()
// When Math.random() is used without any arguments, it returns a random floating point value between 0 and 1:
// Examples:
console.log("Here is a random number " + Math.random());
// However, we can specify the values we want the random number to be within range of using the next method:
// 3. Floor:
// Syntax: Math.floor()
// Math.floor() is used to return the largest whole number that is less than or equal to a specified value. We use this method to get a random whole number within a specific range of numbers, such as 1-10:
// Examples:
let randomNum = Math.floor(Math.random() * 10) + 1 ;
// the syntax of using .floor with .random is:
// Math.floor((Math.random * maxRangeValue) + minRangeValue)
console.log(randomNum);
console.log(
"A new random number between 1 and 10 is " +
Math.floor(Math.random() * 10) + 1
);
console.log(
"Another random number between 1 and 10 is " +
Math.floor(Math.random() * 10) + 1
);
// 4. Round:
// Syntax: Math.round(x) rounds the value x to the nearest whole number
// Examples:
let roundMeUp = Math.round(5.7);
let roundMeDown = Math.round(7.3);
// 5. Exponential Function:
// Syntax: Math.exp(x) raises E to the x power
// Examples:
let raised = Math.exp(5);
// 6. Absolute Value:
// Syntax: Math.abs(x) returns the absolute value of the variable or value in parenthesis
// Examples:
let positive = Math.abs(-24343525);
let negative = -24124214;
let absoluteVal = Math.abs(negative / 2);
// 7. Square Root:
// Syntax: Math.sqrt(x) returns the square root of the value or variable in parenthesis
// Examples:
let sqrt = Math.sqrt(25);
sqrt = Math.pow(sqrt, 2);
console.log(Math.sqrt(sqrt));
// 8. Trigonometric Functions:
// Syntax:
// Sin : Math.sin(x)
// Tan : Math.tan(x)
// Cos : Math.cos(x)
// Arcsin : Math.asin(x)
// Arctan : Math.atan(x)
// Arccos : Math.acos(x)
// Though there are a number of methods for the Math object that we didn't cover, you likely won't need to use them as a beginner programmer. Still, you can read about them here:
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math
// and:
// https://www.w3schools.com/js/js_math.asp
///////////////////////// Exercises /////////////////////////
//1. Declare a new variable named lottery and assign it to a random number between 1 and 3 using the floor and random methods
//2. Write a conditional statement that checks if the value of lottery is equal to 2
// If so, we win the lottery!
// Print the statement to the console with a new random number between 1 and 5 million:
//"You won the lottery! You won $___________"
// Fix the winning value to 2 decimal places
//3. Use the square root function to print the square root of 128,164
//4. Print the absolute value of (-351561 * 15) / 8 to the console
// Declare a new variable named income that is equal to 2500. Declare 4 variables: groceries, rent, utilities, savings. Store varying numeric values in these variables. Ensure at least 2 of the values contain decimal points. Update the 'income' variable to reflect the amount of income left after the four values are 'paid' and therefore subtracted from the income. Write a conditional statement that prints "You have $_____.__ left this month to spend on whatever you want!" if the left over income value is greater than $50.50. Otherwise, print "You should save your $____.__ in case of an emergency this month." Ensure that wherever a monetary value is being printed, the value has two decimal places.
//////////////////////Extra Exercises:
//1. Create two different variables storing two different numbers.
// Find out the value of one of the numbers raised to the other number, using the variable names and the Math.pow() method.
//2. Create a new variable that stores a random number between 1 and 100. Print out your variable.
// Create a second variable that stores the square root of your random number. Print out your second variable.
// Print out your second variable rounded to the nearest whole number.
// Print out your variable as a number with 3 digits.
//3. Create an array that stores 5 numbers.
// In a new variable, multiply the first element of your array by PI (use Math.PI!).
// Print it out with 3 decimal places using the toFixed method
// Print out the value of 5 to the power of 4.
// Print out a random number between 1 and 10 using Math.floor and Math.random.
```

999px

Also see: Tab Triggers