当前位置:网站首页>JS function exercises
JS function exercises
2022-06-25 12:41:00 【Fall in love with*】
1. Use Math.random() Generate a 1-100 The random number , Let the user in the text box , Guess the value . If the number is larger than the random number, it means that the guess is larger , If the number is smaller than the random number, the guess is smaller , Until the numbers are right .
2. Calculator ( Add, subtract, multiply and divide )
3. Set up 5 Textboxes , Calculate the biggest Minimum Average and sum , And display it in a label
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
fieldset {
width: 600px;
margin: auto;
}
div {
width: 500px;
height: 100px;
border: 1px solid black;
}
</style>
</head>
<body>
<fieldset id="">
<legend> Guess number games </legend>
Please enter a number :<input type="number" name="" id="number" value="" />
<button type="button" onclick="guess()"> Click to guess the number </button><br><br>
<div id="spanvalue"></span>
</fieldset>
<script type="text/javascript">
var random = (Math.round(Math.random() * 100) + 0);
console.log(random);
function guess() {
var num = number.value;
if (num > random) {
document.getElementById("spanvalue").innerHTML = " You guessed big ";
} else if (num < random) {
document.getElementById("spanvalue").innerHTML = " You guess it's small ";
} else if (num == random) {
document.getElementById("spanvalue").innerHTML = " You guessed it ";
}
}
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
fieldset {
width: 600px;
margin: auto;
}
input {
margin-top: 15px;
}
button {
margin-top: 15px;
}
</style>
</head>
<body>
<fieldset id="">
<legend> Calculator </legend>
First number :<input type="number" name="" id="first" value="" /><br>
The second number :<input type="number" name="" id="second" value="" /><br>
<button onclick="jisuan(this)">+</button>
<button onclick="jisuan(this)">-</button>
<button onclick="jisuan(this)">*</button>
<button onclick="jisuan(this)">/</button><br>
result :<input type="text" name="" id="result" value="" />
</fieldset>
<script type="text/javascript">
function jisuan(design) {
var a = document.getElementById("first").value;
var b = document.getElementById("second").value;
document.getElementById("result").value = eval(a + design.innerHTML + b);
}
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
</style>
</head>
<body>
<fieldset id="">
<form action="" method="post">
Please enter the first number :<input type="number" id="num1" value="" /><br>
Please enter the second number :<input type="number" id="num2" value="" /><br>
Please enter the third number :<input type="number" id="num3" value="" /><br>
Please enter the fourth number :<input type="number" id="num4" value="" /><br>
Please enter the fifth number :<input type="number" id="num5" value="" /><br>
<button type="button" onclick="cal()"> Show results </button>
</form>
</fieldset>
<script type="text/javascript">
function cal() {
var a = document.getElementById("num1");
var b = document.getElementById("num2");
var c = document.getElementById("num3");
var d = document.getElementById("num4");
var e = document.getElementById("num5");
var a1 = a.value;
var a2 = b.value;
var a3 = c.value;
var a4 = d.value;
var a5 = e.value;
var sum = Number(a1) + Number(a2) + Number(a3) + Number(a4) + Number(a5);
var avg = Number(sum / 5);
var max = Math.max(a1, a2, a3, a4, a5);
var min = Math.min(a1, a2, a3, a4, a5);
document.write(" And for " + sum + "<br/>" + " The average is " + avg + "<br/>" + " The maximum value is " + max + "<br/>" + " The minimum value is " + min);
}
</script>
</body>
</html>
边栏推荐
- 百度搜索稳定性问题分析的故事
- ThinkPHP upload image compression size
- GPS receiver design (1)
- STM32 stores float data in flash
- The whole page turns gray
- Navicat premium view password scheme
- Development with courtesy -- share the source code of the secondary development of the app system of the imitation shopping mall
- ECSHOP quickly purchases goods, simplifies the shopping process, and improves the user experience through one-step shopping
- Disconnected: No supported authentication methods available (server sent: )
- Does sklearex make your sklearn machine learning model training fly fast?
猜你喜欢

微信全文搜索技术优化

Explain AHP in human language (very detailed principle + simple tool implementation)

Singleton mode in PHP to reduce memory consumption

百度搜索稳定性问题分析的故事

Zhangxiaobai's road of penetration (IV) -- detailed explanation of XSS cross site script vulnerabilities

Happy shopkeeper source code -- Introduction to happy shopkeeper system development mode

SDN system method | 9 Access network

Zhangxiaobai's road of penetration (VI) -- the idea and process of SQL injection and the concat series functions and information of SQL_ Schema database explanation

MySQL common interview questions

ECSHOP quickly purchases goods, simplifies the shopping process, and improves the user experience through one-step shopping
随机推荐
浏览器的5种观察器
When MySQL queries fields in JSON format, it takes a property value of JSON data
JS array length is defined
Navicat premium view password scheme
Heyangdao store management system -- share the development source code of heyangdao system
(5) Pyqt5 ---- another method of connecting signals and slots
Figure explanation of fiborache sequence
Laravel echart statistical chart line chart
微信全文搜索技术优化
C program linking SQLSERVER database: instance failed
The whole page turns gray
Initialize the project using the express framework
laravel 9
sudo: ulimit: command not found
Polling and long polling
GPS NMEA protocol, 0183 positioning data format dual mode positioning: gnxxx gps+bd full version
ThinkPHP upload image compression size
ECSHOP whole site custom URL supports directory type
冷启动的最优解决方案
Flutter common commands and problems