练习

1、假如投资的年利率为5%,试求从1000块增长到5000块,需要花费多少年

1000 1000+10000.05=10001.05
1050 1050+10500.05=10501.05
……
5000





循环练习2





练习_第1张图片
1.jpg

2、用while循环重写小明的成绩,如果用户输入不合法就反复输入,直到正确为止





if练习1


练习_第2张图片
360截图20180917204119982.jpg
练习_第3张图片
360截图20180917204129630.jpg

对于成绩大于等于60分的,输出'合格'。低于60分的,输出'不合格'





switch练习1




练习_第4张图片
360截图20180917215057944.jpg

练习_第5张图片
360截图20180917215106299.jpg

4.从键盘接收整数参数,如果该数为1-7,打印对应的星期,否则打印非法参数。




switch练习2




练习_第6张图片
360截图20180917215540604.jpg

练习_第7张图片
360截图20180917215549392.jpg

window.onload = function () {
var value1 = document.getElementById("value1");
var value2 = document.getElementById("value2");
var value3 = document.getElementById("value3");
var btn = document.getElementById("btn");
var select = document.getElementById("select")
btn.onclick = function () { var one, two, bignum;
try { one = value1.value.split(".")[1].length }
catch (e) {
one = 1
}
try {
two = value2.value.split(".")[1].length
} catch (e) {
two = 1 }
bignum = Math.pow(10, Math.max(one, two))
if (value1.value == "" || value2.value == "") {
alert('值不能为空')
value1.value = "";
value2.value = "";
value3.value = ""; }
else if ((value1.value != parseFloat(value1.value)) || (value2.value !=parseFloat(value2.value))) {
alert("输入的值有误")
value1.value = "";
value2.value = "";
value3.value = ""; }
else { if (select.value == "+") {
value = (parseFloat(value1.value) * bignum + parseFloat(value2.value) * bignum) / bignum value3.value = value }
else if (select.value == "-")
{ value = (parseFloat(value1.value) * bignum - parseFloat(value2.value) * bignum) / bignum value3.value = value }
else if (select.value == "") { value = (parseFloat(value1.value) * bignum * parseFloat(value2.value) * bignum) / (bignum * bignum) value3.value = value } else { if (parseFloat(value2.value) == 0)
{ alert("除数不能为零")
value1.value = "";
value2.value = "";
value3.value = ""; }
else { value = ((parseFloat(value1.value) * bignum) / (parseFloat(value2.value) * bignum)) value3.value = value } } } } }




简易计算









你可能感兴趣的:(练习)