Pen Settings



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


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


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.


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 lang="en">
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Number Trivia App</title>
    <!-- Google Fonts -->
    <!-- Stylesheet -->
    <link rel="stylesheet" href="style.css" />
    <div class="container">
      <div class="search-container">
        <input type="num" placeholder="Number" id="num" />
        <button id="get-fact-btn">Get Fact</button>
      <button id="ran-fact-btn">Get Random Fact</button>
      <div class="fact"></div>
    <!-- Script -->
    <script src="script.js"></script>


                * {
  padding: 0;
  margin: 0;
  box-sizing: border-box;
  font-family: "Poppins", sans-serif;
body {
  background-color: #566fff;
.container {
  background-color: #ffffff;
  width: 95vw;
  font-size: 16px;
  max-width: 31.25em;
  padding: 3.5em 2.5em;
  position: absolute;
  transform: translate(-50%, -50%);
  left: 50%;
  top: 50%;
  border-radius: 0.6em;
  box-shadow: 0 1.2em 3em rgba(0, 4, 52, 0.2);
.search-container {
  display: flex;
  justify-content: space-between;
.container input,
.container button {
  font-size: 1.25em;
  outline: none;
  border: none;
  border-radius: 0.4em;
.container input {
  width: 40%;
  border: 1px solid #bdbdbf;
  padding: 0.6em;
.container button {
  width: 55%;
  background-color: #566fff;
  color: #ffffff;
  font-weight: 500;
  padding: 0.7em;
  cursor: pointer;
#ran-fact-btn {
  width: 100%;
  margin-top: 1em;
.fact {
  background-color: #ffffff;
  box-shadow: 0 0 1.2em rgba(0, 4, 52, 0.1);
  margin: 3em auto 0 auto;
  padding: 2.8em 1.8em;
  border-radius: 0.6em;
  border: none;
  border-bottom: 0.6em solid #566fff;
  display: none;
.fact h2 {
  font-size: 2.8em;
  color: #181a34;
.fact p {
  font-size: 1.15em;
  font-weight: 400;
  color: #50526b;
  line-height: 1.8em;
  text-align: justify;
  margin-top: 0.8em;
p.msg {
  text-align: center;
  font-weight: 500;
  color: #181a34;


                let getFactBtn = document.getElementById("get-fact-btn");
let ranFactBtn = document.getElementById("ran-fact-btn");
let fact = document.querySelector(".fact");
let url = "";

let fetchFact = (num) => {
  let finalUrl = url + num;
    .then((resp) => resp.text())
    .then((data) => { = "block";
      fact.innerHTML = `<h2>${num}</h2>
let getFact = () => {
  let num = document.getElementById("num").value;
  //Check if input number is not empty
  //If not empty
  if (num) {
    //Check if number lies between 0 and 300
    //if Yes fetch the fact
    if (num >= 0 && num <= 300) {
    //If number is less than 0 or greater than 300 display error message.
    else { = "block";
      fact.innerHTML = `<p class="msg"> Please enter a number between 0 to 300.</p>`;
  //If input number is empty display error message
  else { = "block";
    fact.innerHTML = `<p class="msg">The input field cannot be empty</p>`;

let getRandomFact = () => {
  //Random number between 0 to 300
  let num = Math.floor(Math.random() * 301);

getFactBtn.addEventListener("click", getFact);
ranFactBtn.addEventListener("click", getRandomFact);
window.addEventListener("load", getRandomFact);