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

              
                <!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Caffeine Analyzer</title>
  <link rel="stylesheet" href="style.css">
</head>
<body>
  <div class="container">
    <a 
      href="https://calculator.institute/caffeine-half-life-calculator-tool/" 
      class="calculator-button" 
      target="_blank" 
      rel="noopener noreferrer"
    >
      Caffeine Half Life Calculator
    </a>
    <h1>Caffeine Analyzer</h1>
    <p>Use this tool to analyze your daily caffeine intake and its impact.</p>
    
    <form id="caffeine-form">
      <label for="drink">Type of Drink:</label>
      <select id="drink" name="drink">
        <option value="coffee">Coffee (95mg per cup)</option>
        <option value="tea">Tea (47mg per cup)</option>
        <option value="soda">Soda (39mg per can)</option>
        <option value="energy">Energy Drink (80mg per can)</option>
      </select>

      <label for="quantity">Number of Servings:</label>
      <input type="number" id="quantity" name="quantity" min="1" placeholder="Enter quantity">

      <button type="button" onclick="analyzeCaffeine()">Analyze</button>
    </form>

    <div id="result"></div>
  </div>
  <script src="script.js"></script>
</body>
</html>
              
            
!

CSS

              
                body {
  font-family: Arial, sans-serif;
  margin: 0;
  padding: 0;
  background-color: #f4f4f9;
  color: #333;
}

.container {
  max-width: 600px;
  margin: 50px auto;
  padding: 20px;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  text-align: center;
}

h1 {
  font-size: 24px;
  margin-bottom: 20px;
}

p {
  font-size: 16px;
  margin-bottom: 20px;
}

label {
  display: block;
  margin: 10px 0 5px;
}

input, select {
  width: 100%;
  padding: 10px;
  margin-bottom: 20px;
  border: 1px solid #ccc;
  border-radius: 4px;
}

button {
  background-color: #007bff;
  color: #fff;
  border: none;
  padding: 10px 15px;
  border-radius: 4px;
  cursor: pointer;
}

button:hover {
  background-color: #0056b3;
}

.calculator-button {
  display: inline-block;
  background-color: #28a745;
  color: #fff;
  padding: 15px 20px;
  border: none;
  border-radius: 5px;
  font-size: 16px;
  cursor: pointer;
  margin-bottom: 20px;
}

.calculator-button:hover {
  background-color: #218838;
}

#result {
  font-size: 18px;
  margin-top: 20px;
  color: #555;
}
              
            
!

JS

              
                function analyzeCaffeine() {
  const drink = document.getElementById("drink").value;
  const quantity = parseInt(document.getElementById("quantity").value);

  if (!quantity || quantity <= 0) {
    alert("Please enter a valid quantity!");
    return;
  }

  let caffeineContent = 0;

  switch (drink) {
    case "coffee":
      caffeineContent = 95;
      break;
    case "tea":
      caffeineContent = 47;
      break;
    case "soda":
      caffeineContent = 39;
      break;
    case "energy":
      caffeineContent = 80;
      break;
    default:
      caffeineContent = 0;
  }

  const totalCaffeine = caffeineContent * quantity;
  let message = `You consumed ${totalCaffeine} mg of caffeine.`;

  if (totalCaffeine > 400) {
    message += " This is above the recommended daily limit. Please reduce your intake!";
  } else {
    message += " This is within the safe daily limit. Keep it balanced!";
  }

  document.getElementById("result").innerHTML = message;
}
              
            
!
999px

Console