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. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ 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

              
                <div class="container" id="js-box">
  <p>Click on 'Predict' to get a message about your next life!</p>
</div>

<button id="predict-button">Predict</button>
              
            
!

CSS

              
                .container {
  font-family: arial;
  width: 400px;
  height: 150px;
  border: solid 2px #1a1a1a;
  padding: 10px 20px;
  margin-bottom: 20px;
}
              
            
!

JS

              
                // Step 1: Create function to generate a random number. Later in the program it will take the length of an array as argument and use it as a maximum value.
function randomNumber(num) {
    return Math.floor(Math.random() * num)
};

// Step 2: Create object to store 3 types of messages
// Step 3: Create getter for each type of messages to return a random message
// Step 4: Create object method to combine the randomly selected messages into a single one and print it
const storedMessages = {
    _willBecome: [
        "an astronaut",
        "a magician",
        "a galactic explorer",
        "a technology master",
        "a guru of wisdom",
        "an inventor",
        "a leader of a space colony",
        "a science master",
        "an augmented reality artist",
        "a space farmer"
    ],
    _willBeAbleTo: [
        "teleport",
        "communicate via telepathy",
        "sing like Mariah",
        "jump 100 meters",
        "create any object you can think of",
        "handle and work with energies",
        "travel through time",
        "send a parcel from Mars to Jupiter",
        "speak with animals",
        "change your age"
    ],
    _willOwn: [
        "a magic wand",
        "a space ship",
        "a space factory",
        "a time machine",
        "a flying house",
        "a plant that can speak",
        "an invisible car",
        "a house robot",
        "a self running kitchen",
        "a moon"
    ],

    get willBecome () {
        let randWillBecome = this._willBecome[randomNumber(this._willBecome.length)];
        return randWillBecome;
    },

    get willBeAbleTo () {
        let randWillBeAbleTo = this._willBeAbleTo[randomNumber(this._willBeAbleTo.length)];
        return randWillBeAbleTo;
    },

    get willOwn () {
        let randWillOwn = this._willOwn[randomNumber(this._willOwn.length)];
        return randWillOwn;
    },

    predict () {
        let message = [
            'In your next life:',
            `- you will become ${this.willBecome}.`,
            `- you will be able to ${this.willBeAbleTo}.`,
            `- you will own ${this.willOwn}.`
        ];
        let formattedMessage = message.join("<br>")
        return formattedMessage;
    }
};

const runButton = document.getElementById("predict-button");
const htmlContainer = document.getElementById("js-box");

runButton.addEventListener("click", function() {
    return htmlContainer.innerHTML = storedMessages.predict();
});

              
            
!
999px

Console