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.

Quick-add: + add another resource

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.

Quick-add: + add another resource

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.

            
              <div class="eight-ball">
  <div class="sheen">
    <div class="viewer">
      <div id="message"><p id="messageText"></p></div>
    </div>
  </div>
</div>
<div class="askContainer">
  <h3 id="currentQuestion"></h3>
  <input id="questionBox" type="text">
  <button id="ask">Ask</button>
</div>
            
          
!
            
              body {
  background:linear-gradient(#0e0f47, #519996);
  display:flex;
  flex-direction:column;
  font-family: 'Montserrat', sans-serif;
}

.eight-ball {
  background:radial-gradient(farthest-corner at 15px 15px, #333, #000);
  width:500px;
  height:500px;
  border-radius:50%;
  margin:auto;
  display:flex;
}

.sheen {
  height:450px;
  width:450px;
  margin:auto;
  border-radius:50%;
  box-shadow:-15px -15px 5px -15px #999;
}

.viewer {
  background-color:#000;
  border: solid .25em #333;
  height:190px;
  width:190px;
  border-radius:50%;
  margin:80px auto;
  display:flex;
}

#message {
  height: 0;
  width: 0;
  border-left: 75px solid transparent;
  border-right: 75px solid transparent;
  border-top: 120px solid darkblue;
  margin: 45px auto;
  transition: opacity 2s ease-in-out;
  opacity: 0;
}

#messageText {
  width:95px;
  color:white;
  margin-top:-110px;
  margin-left: -50px;
  text-align:center;
}

.askContainer {
  margin:40px auto;
}

#currentQuestion {
  text-align:center;
  color:white;
  margin-top:-20px;
}

#questionBox {
  width:400px; 
  border:0;
  border-radius: 5px;
  padding:10px;
}

#ask {
  background-color:transparent;
  border:0;
  color:darkblue;
  font-weight:bold;
  margin-left:-40px;
}
            
          
!
            
              const output = document.getElementById('messageText');
const triangle = document.getElementById('message');
const questionBox = document.getElementById('questionBox');
const currentQuestion = document.getElementById('currentQuestion');
const askButton = document.getElementById('ask');
const responses = ["It is certain","It is decidedly so","Without a doubt","Yes, definitely","You may rely on it","As I see it, yes","Most likely","Outlook good","Yes","Signs point to yes","Reply hazy try again","Ask again later","Better not tell you now","Cannot predict now","Concentrate and ask again","Don't count on it","My reply is no","My sources say no","Outlook not so good","Very doubtful"];

const askThe8Ball = function() {
  currentQuestion.innerHTML = questionBox.value;
  let randResponse = Math.floor(Math.random() * responses.length);
  output.innerHTML = responses[randResponse];
  triangle.style.opacity = '1';
  // I should read up on async/await because this isn't a good solution for 2016...
  askButton.disabled = true;
  setTimeout(fadeOut, 4000);
};

function fadeOut() {
  triangle.style.opacity = '0';
  askButton.disabled = false;
}

askButton.addEventListener('click', askThe8Ball);
            
          
!
999px
Loading ..................

Console