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.

            
              <body>
  <div id="guessing-container">
    <div id="guessing-text">
      <div id="guessing-inner">
        <!-- this is where the user/computer chats will go -->
      </div>
    </div>
    <input id="userGuess" type="text" placeholder="Guess!">
  </div>
  <!-- close #guessing-div -->
</body>
            
          
!
            
              /* compiled from Sass */

/* to add: responsive behavior, animation for computer text */
html {
  background-color: #9496A5;
}
#guessing-container {
  margin: 50px auto;
  position: relative;
  max-width: 600px;
  padding-bottom: 57px;
  font-family: 'Lucida Sans', Arial, Helvetica, sans-serif;
  font-size: 0.9em; }
  #guessing-container #guessing-text {
    overflow-y: scroll;
    height: 300px;
    background-color: #F1F1F1;
    padding: 10px;
    border: solid 3px #545454;
    border-bottom: 0; }
  #guessing-container #guessing-inner {
    height: 301px; }
  #guessing-container span {
    display: inline-block;
    color: #5a5a5a;
    padding: 8px 15px;
    border-radius: 20px;
    margin-bottom: 15px;
    position: relative; }
  #guessing-container #userGuess {
    height: 50px;
    position: absolute;
    bottom: 0;
    border: 0;
    left: 0;
    -webkit-appearance: none;
    -moz-appearance: none;
    -ms-appearance: none;
    -o-appearance: none;
    appearance: none;
    border-bottom: #61F1C9 solid 5px;
    width: 100%;
    width: calc(100% - 2px);
    font-size: 1.1em;
    background-color: #444;
    text-indent: 15px;
    color: #DEDEDE;
    letter-spacing: 1px;
    outline: none; }
  #guessing-container .computerTxt-container {
    display: block; }
    #guessing-container .computerTxt-container i {
      background-color: #5a5a5a;
      color: #ececec;
      padding: 10px;
      border-radius: 50%;
      font-size: 1.1em; }
  #guessing-container .computerTxt {
    background-color: #FFDE90;
    text-align: left;
    margin-left: 20px; }
  #guessing-container .computerTxt.new-color {
    background-color: #BCDEFB; }
  #guessing-container .computerTxt::before {
    content: '';
    position: absolute;
    width: 0;
    height: 0;
    left: -10px;
    border: 9px solid;
    border-color: transparent transparent #FFDE90; }
  #guessing-container .computerTxt.new-color::before {
    border-color: transparent transparent #BCDEFB; }
  #guessing-container .userTxt-container {
    text-align: right; }
    #guessing-container .userTxt-container i {
      padding: 10px 12px;
      border-radius: 50%;
      font-size: 1.1em;
      margin-right: 5px;
      background-color: #5a5a5a;
      color: #ececec; }
  #guessing-container .userTxt {
    background-color: #61F1C9;
    text-align: right;
    margin-right: 20px; }
  #guessing-container .userTxt::after {
    content: '';
    position: absolute;
    width: 0;
    height: 0;
    right: -9px;
    border: 9px solid;
    border-color: transparent transparent #61F1C9; }
  #guessing-container input[type=number]::-webkit-inner-spin-button,
  #guessing-container input[type=number]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0; }

/*# sourceMappingURL=main.css.map */

            
          
!
            
              $( document ).ready(function() {
	//declare global variables
	var userNumber = '';
	// var userReply = '';
	var userWon = false;
	var textIsYellow = true;
	var computerNumber;
	var randomEmoji;
	var emojis = ['(و˃ᴗ˂)و', '\(^○^)人(^○^)/', '(✿ ♥‿♥)', '\\(^-^)/', '٩( ´◡` )۶', '(つ◕౪◕)つ━☆゚.*・。゚', '♪ヽ( ⌒o⌒)/', '(~˘▾˘)~'];
	var doesNotCompute = ['Does not compute へ[ •́‸ •̀ ]ʋ', 'I only understand numbers (◕︿◕✿)', 'lol wut (・_・ヾ', 'y u no write numbers?! (ლಠ益ಠ)ლ', '(╯°□°)╯︵ ┻━┻', '(◡ ﹏ ◡)', 'ಠ_ಠ'];
	var sadface = 0;
	//initate game!
	playGame();

	function playGame() {
		// pick random number and initiate prompt
		initiateGuessing();
		
		// user picks a number
		$('#userGuess').keydown(function(e){
			// submit on enter
			if (e.keyCode === 13) {
				// user num = input
				userNumber = $('#userGuess').val();
				// print user num in html
				printUserReply(userNumber);
				// clear input 
				$('#userGuess').val('');
				// check if usernum = winner
				checkMyNum(userNumber);
				// scroll to bottom of chatbox
				scrollDown();
				//if player won, play again
				playAgain(userWon);
			}
		});
	}	

	function checkMyNum(guessNum) {
		var ifNumber = $.isNumeric(userNumber);
		if (ifNumber === false) {
			printComputerReply(doesNotCompute[sadface], textIsYellow);
			scrollDown();
			sadface++;
			if (sadface === doesNotCompute.length) {
				sadface = 0;
			}
			userWon = false;
			return;
		}
		else {
			if (computerNumber < userNumber) {
				printComputerReply('Too high! Guess again', textIsYellow);
				return userWon = false;
			}
			else if (computerNumber > userNumber){
				printComputerReply('Too low! Guess again', textIsYellow);
				return userWon = false;
			}
			else {
				// pick random emoji for the you win msg
				randomEmoji = randomEmojis();
				// print winning msg
				printComputerReply('You win! ' + randomEmoji, textIsYellow);
				printComputerReply('Let\'s play again!', textIsYellow);
				return userWon = true;
			}
		}	
	}

	function playAgain(userWon) {
		if (userWon) {
			//set new bg color for computer
			textIsYellow = !textIsYellow;
			//wait a minute before initiating new game
			setTimeout(initiateGuessing, 1350);
			return textIsYellow;
		}
	}

	function randomNum() {
		return Math.ceil(Math.random()*100);
	}

	function randomEmojis() {
		return emojis[Math.floor(Math.random()*emojis.length)];
	}

	function initiateGuessing() {
		// computer picks a number from 1-100
		computerNumber = randomNum();	
		// print in console for hacks
		console.log('Guessing game hacks: ' + computerNumber);
		// print initiate prompt
		printComputerReply('I\'m thinking of a number between 1 &amp; 100', textIsYellow);
		// focus on guess field - hide on portfolio site
		// $('#userGuess').focus();
		scrollDown();
		return computerNumber;
	}

	function printComputerReply(computerReply, textIsYellow) {
		if (textIsYellow) {
			$('#guessing-inner').append('<div class="computerTxt-container"><i class="fa fa-terminal"></i><span class="computerTxt">' + computerReply + '</span></div>');
		}
		else {
			$('#guessing-inner').append('<div class="computerTxt-container"><i class="fa fa-terminal"></i><span class="computerTxt new-color">' + computerReply + '</span></div>');
		}
		
	}

	function printUserReply(text) {
		$('#guessing-inner').append('<div class="userTxt-container"><span class="userTxt">' + text + '</span><i class="fa fa-user"></i></div>');
	}

	function scrollDown() {
		$('#guessing-text').scrollTo($('#guessing-text')[0].scrollHeight, 350);
	}

});

/*

(و˃ᴗ˂)و

(╯°□°)╯︵ ┻━┻

ʕ·ᴥ·ʔ

\(^○^)人(^○^)/

ಠಿ ˑ̫ ಠಿ

\(^ω^\)

ヘ(^0^)ヘ

(~˘▾˘)~

┗(^0^)┓

(つ◕౪◕)つ━☆゚.*・。゚

♪ヽ( ⌒o⌒)/

٩( ´◡` )۶

(◡ ﹏ ◡)

(◕ ﹏ ◕)

(╥﹏╥)

(Ͼ˳Ͽ)

ಠ_ಠ

へ[ •́‸ •̀ ]ʋ

(◕︿◕✿)

┏༼ ◉ ╭╮ ◉༽┓ 

(⌯˃̶᷄ ﹏ ˂̶᷄⌯)

(ლಠ益ಠ)ლ

(・_・ヾ

*/



            
          
!
999px
🕑 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 ..................

Console