cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation


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.

              <link href="https://fonts.googleapis.com/css?family=Karla:400,700" rel="stylesheet">

<div class = 'container'>
<div class = 'flex-column'>

<p class = 'info'>Enter a number with decimals.</p>  
<input type = 'number' id ='number'>
<button type = 'button' id = 'submit'>Submit</button>

<h2>Your Number</h2>
<div id = 'user-number'> </div>

<h2>3 Decimals</h2>
<div id ='three-decimals'> </div>

<h2>3 Digits</h2>
<div id = 'three-digits'> </div>

              body {
  font-family: 'Karla', sans-serif;
  background-color: #fcfcfc;
  width: 100vw;

.container {
  background-color: #efefef;
  width: 400px;
  height: 85vh;
  margin: 0 auto;
  margin-top: 25px;
  border-radius: 8px;
  -webkit-box-shadow: 0px 0px 8px -2px rgba(0,0,0,0.40);
  -moz-box-shadow: 0px 0px 8px -2px rgba(0,0,0,0.40);
  box-shadow: 0px 0px 8px -2px rgba(0,0,0,0.40);

.flex-column {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 20px;

.info {
  margin-bottom: 20px;

#number {
  border: none;
  height: 30px;
  width: 200px;
  background-color: #fff;
  border-radius: 5px;
  margin-bottom: 10px;


input[type='number'] {
  font-family: 'Karla', sans-serif;
  font-size: 24px;

input:-webkit-autofill:active {
    transition: background-color 5000s ease-in-out 0s;

#submit {
  background-color: #7fdbb7;
  border: none;
  border-radius: 5px;
  font-family: 'Karla', sans-serif;
  font-size: 20px;
  width: 120px;
  cursor: pointer;
  -webkit-box-shadow: 0px 0px 8px -2px rgba(0,0,0,0.40);
  -moz-box-shadow: 0px 0px 8px -2px rgba(0,0,0,0.40);
  box-shadow: 0px 0px 8px -2px rgba(0,0,0,0.40);
  transition: 0.1s linear all;

#submit:hover {
  box-shadow: none;
  background-color: #45d19a;

#submit:focus {
 outline: 0;

h2 {
  font-size: 20px;
  margin-bottom: 0;

p {
  margin-bottom: 0;

              //Add event listener for clicked submit.
document.getElementById('submit').addEventListener('click', function(){

//Get the submited value as a string.  
var number = document.getElementById('number').value;
//Convert string to a number.
var numberInt = parseFloat(number);

//Surround the numbers in a <p> tag.
var userNumber = '<p>' + numberInt + '</p>';
var threeDec = '<p>' + numberInt.toFixed(3) + '</p>';
var threeDig = '<p>' + numberInt.toPrecision(3) + '</p>';

//Create variables of the divs the numbers will be displayed in.  
var usrNmbr = document.getElementById('user-number');
var threeDecimals = document.getElementById('three-decimals');
var threeDigits = document.getElementById('three-digits');

//Push the <p>number</p> variables into the divs using innerHTML.
usrNmbr.innerHTML = userNumber;
threeDecimals.innerHTML = threeDec;
threeDigits.innerHTML = threeDig;

🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................