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

              
                
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<style>
body {
    font-family: monospace;
    font-size: 20px;
    background-color: #333333;
    color: #f1f1f1;
}
</style>
</head>
<body>

    <h1>MY GAME JS</h1>
    <div><label for="name1">Choose name for Player1:</label>
    <br>
    <input type="text" id="name1" />
    <br>
    <label for="proff1">Choose proffession for Player1:</label>
    <br>
    <input type="text" id="proff1" />
    <button onclick="cp1()">Confirm</button>
    <br>
    <br>
    </div>
    <div>
    <label for="name2">Choose name for Player2:</label>
    <br>
    <input type="text" id="name2" />
    <br>
    <label for="proff2">Choose proffession for Player2:</label>
    <br>
    <input type="text" id="proff2" />
    <button onclick="cp2()">Confirm</button>
    </div>
    <div id="player1"></div>
    <div id="player2"></div>
  <!-- For testing if value of p1 can be reassigned
  <div><button onclick="changep1()">Change P1</button></div>
  <div id="p1changed"></div>
  -->

<script>    
    function Barbarian (name) {
            this.name = name;
            this.proff = 'Barbarian';
            this.hp = 400;
            this.ep = 20;
            this.attack = 20;
            this.defense = 20;
            this.intelligence = 5;
            this.dodge = 50;
        }
    
    
    class Assassin {
        constructor(name) {
            this.name = name;
            this.proff = 'Assassin';
            this.hp = 50;
            this.ep = 50;
            this.attack = 60;
            this.defense = 0;
            this.e_defense = 0;
            this.dodge = 70;
        }
    }
    //Creating Player1
    const cp1 = () => {
        const p1name = () =>{
        return document.getElementById('name1').value;
        }
     const p1proff = () =>{
        return eval(document.getElementById('proff1').value);
        }
        const name = p1name();
        const proff = p1proff();
        p1 = new proff(name);
        //Line below is only for testing if object p1 is created properly
        document.getElementById("player1").innerHTML = `Player1: ${p1.name}, Proffession: ${p1.proff}, HP: ${p1.hp}`;
    }
    
    //Creating Player2
    const cp2 = () => {
        const p2name = () =>{
        return document.getElementById('name2').value;
        }
     const p2proff = () =>{
        return eval(document.getElementById('proff2').value);
        }
        const name = p2name();
        const proff = p2proff();
        p2 = new proff(name);
        //Line below is only for testing if object p2 is created properly
        document.getElementById("player2").innerHTML = `Player2: ${p2.name}, Proffession: ${p2.proff}, HP: ${p2.hp}`;
    }
    
    //Function below is for testing if value of p1 can be reassigned
    /* 
    const changep1 = () =>{
      console.log(p1);
      p1 = 'Value changed!';
      document.getElementById("p1changed").innerHTML = p1;
      console.log(p1);
    }
    */
    
</script>
</body>
</html>
              
            
!

CSS

              
                
              
            
!

JS

              
                
              
            
!
999px

Console