html acerte邻numero.html

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了html acerte邻numero.html相关的知识,希望对你有一定的参考价值。

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8">
	<title>Acerte o Número</title>
	<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js" type="text/javascript"></script>
	<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet">
	<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
	<script>
		$(function(){
			// Gerando número aleatório entre 0 e 100
			var numSecret = 50; // Math.floor((Math.random() * 100) + 0);
			$('.identical, .greater, .lower, .attempts').hide();
			var numAttempts = 0;
			$('.btn').on('click', function(event){
				event.preventDefault();
				var numChosen = parseFloat($('.numChosen').val());
				if(numChosen >= 0 && numChosen <= 100) {
					if(numChosen === numSecret){
						numAttempts++;
						$('.numAttempts').text(numAttempts);
						$('.attempts, .identical').fadeIn('slow');
						$('.numSecret').text(numSecret);
						$('.greater, .lower').hide();
						$('.numChosen').val('');
						numAttempts = 0
					}
					if(numChosen > numSecret){
						numAttempts++;
						$('.numAttempts').text(numAttempts);
						$('.attempts, .greater').fadeIn('slow');
						$('.lower, .identical').hide();
					}
					if(numChosen < numSecret){
						numAttempts++;
						$('.numAttempts').text(numAttempts);
						$('.attempts, .lower').fadeIn('slow');
						$('.greater, .identical').hide();
					}
				}
				else {
					alert('O número precisa estar entre 0 e 100.');
					$('.numChosen').val('');
					$('.identical, .greater, .lower').hide();
				}
			});
		});
	</script>
</head>
<body>
	<div class="container">
    	<div class="row">
	        <div class="col-md-7 col-md-offset-5">
	            <h4>Digite um número entre 0 e 100</h4>
	            <form class="form-horizontal">
	                <div class="form-group col-lg-12">
	                    <input type="text" class="numChosen input-sm">
	                    <input type="button" class="btn btn-primary btn-sm" value="Tentar">
	                </div>
	                <div class="form-group col-lg-12">
	                    <p class="attempts">Você tentou <span class="numAttempts badge"></span> vez(es).</p>
	                </div>
	                <div class="form-group col-lg-12">
	                    <span class="alert alert-success identical input-sm">
	                    	PARABÉNS, o número secreto é <span class="numSecret badge"></span>
	                    </span>
	                    <span class="alert alert-danger greater input-sm">
	                    	O número escolhido é <span class="badge">MAIOR</span> do que o secreto.
	                    </span>
	                    <span class="alert alert-danger lower input-sm">
	                    	O número escolhido é <span class="badge">MENOR</span> do que o secreto.
	                    </span>
	                </div>
	            </form>
	        </div>
	    </div>
    </div>
</body>
</html>

以上是关于html acerte邻numero.html的主要内容,如果未能解决你的问题,请参考以下文章

typescript 邻10.ts

typescript 邻9.ts

typescript 邻8.ts

typescript 邻7.ts

typescript 邻7.ts

typescript 邻6.ts