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

              
                
<form id="myForm">
	<h1>Paint calculator</h1>
	
	<input-field>
		<label for="w">Width (in feet)</label>
		<input id="w" type="number" min="1" value="2" required>
	</input-field>
	
	<input-field>
		<label for="h">Height (in feet)</label>
		<input id="h" type="number" min="1" value="2" required>
	</input-field>
	
	<output>
		<!-- message here -->
	</output>
	
<!-- 	how many gallons needed at 400 square feet per gallon... -->
	
	<button type='submit'>Send order</button>
</form>



              
            
!

CSS

              
                
form {
	display: grid;
	gap: 20px;
	padding: 30px;
	border: 1px solid black;
}

form button {
	justify-self: start;
}

input-field {
	display: grid;
	gap: 4px;
	max-width: 300px;
}

output {
	background-color: #c8f5c8;
	padding: .5em 1em;
	width: max-content;
	border-radius: 8px;
}

body {
	padding: 30px;
}


h1 {
	font-weight: 700;
}
              
            
!

JS

              
                console.clear();
// probably need input / form √
// the two dimentions
// 	width and height (nouns)
// note the unit of ft or something
// multiply (calculate)(verb) those width and height to get the full area
// how much paint covers a square foot or something...
// a way to present that information (create message for user output)

// if user inputs new information... (the 'input' event can track that)
// clear message 
// until they hit submit : and then rebuild the message

function area(width, height) {
	return width * height;
}

function message(w, h, a) {
	// return `With a width of ${w} feet and height of ${h} feet, the total area would be ${a} square feet.`; // This one is hard to read... maybe not great UX
	return `
		${a} square feet.
	`;
}

// this way the function stands on its own. It can be tested alone and composed in more places
function handleAreaCalculation() {
	var theWidth = document.querySelector('#w').value;
	var theHeight = document.querySelector('#h').value;
	var areaTotal = area(theWidth, theHeight);
	var outputArea = document.querySelector('output');
	outputArea.textContent = message(theWidth, theHeight, areaTotal);
}

var form = document.querySelector('#myForm');

form.addEventListener('input', function() {
	handleAreaCalculation();
});

// run as a default / so user see how the form works (in this case)
handleAreaCalculation();


// function clearMessage() {
// 	var outputArea = document.querySelector('output');
// 	outputArea.textContent = "";
// }

// form.addEventListener('input', function() {
// 	clearMessage(); // so the message isn't out of date when the user is choosing numbers
// });

function handleOrder() {
	console.log('Send order message to buy appropriate paint gallons');
}

form.addEventListener('submit', function(event) {
	event.preventDefault();
	handleOrder();
	// clear info?
});

              
            
!
999px

Console