# Sweater Cost Calculator

## In this example below you will see how to do a Sweater Cost Calculator with some HTML / CSS and Javascript

This awesome code was written by lowbelly, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
• HTML
• CSS
• JavaScript
``````
<h1>OMG, you could sell those sweaters! How much do they cost?</h1>
<p>Enter the number of weeks it takes to make a sweater and press return.</p>
<input type="text" id="weeks" />
<h2 id="results"></h2>
``````
``````

body {
background-color:lightpink;
}
img {
width: 200px;
}

``````
``````
// enter the number of weeks

// These sweaters cost \$x, how many would you like?
var workingHoursInWeeks = 56;
var minWage = 9.25;
var results = document.getElementById("results");

// weeks * working hours * minimum wage
function sweaterCostCalc(weeks){
var sweaterCost = weeks * workingHoursInWeeks * minWage;
return sweaterCost;
}

{
nStr += '';
var x = nStr.split('.');
var x1 = x[0];
var x2 = x.length > 1 ? '.' + x[1] : '';
var rgx = /(\d+)(\d{3})/;
while (rgx.test(x1)) {
x1 = x1.replace(rgx, '\$1' + ',' + '\$2');
}
return x1 + x2;
}

var userEnteredWeeks = document.getElementById("weeks").value;
var Cost = sweaterCostCalc(userEnteredWeeks);

if (event.keyCode == 13){
results.innerHTML = "These sweaters cost \$" + totalCost + " each. How many would you like?";
}

});

``````