Pen Settings



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


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


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.


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.


                <button id="btnPlay">Play Game!</button>




                var btnPlay = document.getElementById('btnPlay');

const random_names = ["Lily", "Chance", "Samuel", "Chris", "Malakai", "Julia", "Brandon"];

btnPlay.onclick = function() {
  alert("Welcome to my game! Use the OK and Cancel buttons to choose your adventure. This example uses three JavaScript functions to show you messages and ask you questions: alert(), confirm(), and prompt().");
  var name = prompt("What is your name?");
  if (name == null || name.length < 1) {
    alert("You don't have a name?");
    alert("Okay, I'll pick one for you.")
    name = getRandomName();
    alert("Your name is " + name);
  var choice1 = confirm("You are on the playground and you find a mysterious red lamp. Do you pick it up?");
  if (choice1 == true) {
    alert("The lamp seems to be made of glass. When you shake it, the inside lights up with tiny blue sparks that look like stars.");
    choice2 = confirm("There's still time to put the lamp down and walk away. Do you rub the lamp?");
    if (choice2) {
      alert("A genie pops out of the bottle!")
      var genie_name = prompt("What is the genie's name?");
      if (genie_name == null || genie_name.length < 1) {
        alert("You didn't give the genie a name? Oh, man.")
        alert("Okay, I'll do it for you.");
        genie_name = getRandomName();
        alert("The genie's name is " + genie_name);
      alert(`The genie says in a booming voice, "Hello there, ${name}. My name is ${genie_name}. I am here to grant you three wishes."`);
      for (var i = 0; i < 3; i++) {
        var wish = prompt(genie_name + ": What is your wish?");
        alert(genie_name + ": I have granted your wish! " + wish);
      alert(`Great work, ${name}. Your wishes made the world a better place!`);
  } else {
    alert("Recess is over, and nothing bad happened!")

function getRandomName() {
  return random_names[Math.floor(Math.random() * random_names.length)];