Pen Settings

HTML

CSS

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

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

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.

HTML

              
                <h1>Here is a simple example of doubling your pennies everyday.</h1>
		<h3>You have one penny to start with. What will be your daily penny amount?</h3>
		<button id="doubleItButton" type="button">Double It</button>
		<p>Amount: <span id="dailyAmount">1 penny</span></p>
		<h3>See it all in fast foward action.</h3>
		<button id="summaryButton" type="button">Click Me</button>
		<div id="sum"></div>
		<div id="finalSum"></div>
              
            
!

CSS

              
                #sum p, #finalSum p{
				border: 1px solid black;
				padding: 4px;
				margin: 0;
				width:400px;
			}
              
            
!

JS

              
                //getting the elements that will be used to add text or used for click events
		    const dblButton = document.querySelector("#doubleItButton");
		    const sumButton = document.querySelector("#summaryButton");
		    const dailyAmnt = document.querySelector("#dailyAmount");
		    const ovrallSum = document.querySelector("#sum");
		    const finSum = document.querySelector("#finalSum");

           
		    //doubleIt will chnage the dailyPenny value each time it is called and print the current calculated value of pennies
            let dailyPenny = 1;
            let doubleIt = () => {return dailyPenny *= 2;};
            dblButton.addEventListener("click", (e) =>{
            	e.preventDefault();
            	dailyAmnt.innerHTML = `${doubleIt()} pennies`;
            });

		    /*
		    CONST PTAG : creation of new p tag; will be added dynamically through a click event
			LET DONE: varibale that will change from false to true once function is complete; will prevent function from running again once done equals true.
			CLICK EVENT:addEventListener() method is called on "sumButton" that will run a function that takes a penny amount and multiplies its own value by two for each iteration; at each iteration an element is created with a new penny amount value and then appended to its parent node. 
		    */
		    const pTag = document.createElement("p");
		    let done = false;
            sumButton.addEventListener("click", (e) => {
            	e.preventDefault();
            	let penny = 1;
            	if(!done){
            		for(let i=1; i<=365; i++){
            			const elemSet = document.createElement("p");
						penny*=2;								
           		    	ovrallSum.appendChild(elemSet).appendChild(document.createTextNode(`Day ${i}: ${penny} pennies` ));          		
            		}  
            		finSum.appendChild(pTag).appendChild(document.createTextNode(`Total: ${penny} pennies`));            		
            	}
            	else{
            		alert(`The claculation has already been completed.`);
            	//done = true;
           		 }
           		 done = true;
            });

              
            
!
999px

Console