Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's 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 it's URL and the proper URL extention.

+ 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

Save Automatically?

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

              
                
              
            
!

CSS

              
                
              
            
!

JS

              
                // CHALLENGE 1
function celciusToFahrenheit (celcius) {
    return celcius * 9/5 + 32;
}

console.log(celciusToFahrenheit(44));


// CHALLENGE 2
function sum (array) {
    return array.reduce((currentSum, x) => currentSum + x);
}

console.log(sum([100,200,300,400]));


// CHALLENGE 3
// using loops
function reverse1 (string) {
    let reversed = "";
    for (let i = string.length - 1; i >= 0; i--)
        reversed += string[i];
    return reversed;
}

// using built in array methods
function reverse2 (string) {
    return [...string].reverse().join("");
}

console.log(reverse1("Hello"));
console.log(reverse2("Hello"));

console.log(reverse1("this string is revered"));

console.log("World".split(""))
// using spread operator to split arrays, is exactly the same as above
console.log([..."World"]);


// CHALLENGE 4
for (let i = 1; i <= 100; i++) {
    if (i % 3 === 0 && i % 5 === 0)
        console.log("FizzBuzz")
    else if (i % 3 === 0)
        console.log("Fizz")
    else if (i % 5 === 0)
        console.log("Buzz")
    else
        console.log(i)
}

// a more functional way to approach fizzbuzz
function fizzbuzzchecker(number) {
    if (number % 3 === 0 && number % 5 === 0)
        return "FizzBuzz"
    if (number % 3 === 0)
        return "Fizz"
    if (number % 5 === 0)
        return "Buzz"
    return number;
}

// a more compact / "smart" way to approach fizzbuzz
function fizzbuzzchecker2 (number) {
    let results = "";
    if (number % 3 === 0)
        results += "Fizz";
    if (number % 5 === 0)
        results += "Buzz";
    // if (results === "")
    //     return number;
    // else
    //     return results;

    // ternary operator: does the same as the if else statement above
    return results === "" ? number : results;
}

for (let i = 1; i <= 100; i++) {
    console.log(fizzbuzzchecker2(i))
}


// CHALLENGE 5
function factorial (number) {
    let results = 1;
    for (let i = number; i > 0; i--)
        results *= i;
    return results;
}

function factorial2 (number) {
    if (number === 0)
        return 1;
    return number * factorial2 (number - 1);
}

console.log(factorial(5));
console.log(factorial2(5));
              
            
!
999px

Console