var A = prompt("输入A的值","")
var B = prompt("输入B的值","")
var tmp = A
A = B
B = tmp
console.log("A:" + A + ",B:" + B)
//2.
var num = 1234
var str = num + ""
console.log("是" + str.length + "位数")
for(var i = str.length - 1 i >= 0 i--){
console.log(str.charAt(i))
}
//3.
var sum = 0
for(var i = 锋晌0 i < 100 i++){
var rand = Math.floor(Math.random() * 10)
sum += rand
}
console.log(sum)
//4.
var A
while(true){
A = prompt("输入一个整数","")
if(A % 1 != 0){
continue
}
var 宴胡isPrime = true
for(var i = 2 i <= A/2 i++){
晌基拦 if(A % i == 0){
isPrime = false
break
}
}
if(isPrime){
alert(A + "是素数")
}else{
alert(A + "不是素数")
}
break
}
//5.
var n = 2,
a = 1,
b = 2,
c = b / a
while (n <= 20) {
var tmp = a
a = b
b = tmp + b
c += b / a
n++
}
console.log(c)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML>
<HEAD>
<TITLE>New Document </TITLE>
<script language="javascript">
<!--//
String.prototype.RandomNumber=function (){var arg=argumentsvar n=1if(arg.length!=0){n=(!isNaN(parseInt(arg[0])))?parseInt(arg[0]):1}var chars=['0','1'洞老,'2','3','4','5','6','7','8','9']var res=""for(var i=0i<ni++){var id=Math.ceil(Math.random()*9)res+=chars[id]}return res}
function getCacNum(){
var ia = []
for (var i=0i<1000i++)
{
if (i!=0 &&i%3==0 &&i%5==0 &&i%7==0)
{
ia.push(i)
}
}
var restr = ""
for (var i=0i<ia.lengthi++)
{
if(i!=0 &&i%6==0){
restr+="\r\n"
restr+=ia[i]
}else{
if (restr == "")
{
restr = ia[i]
}else{
restr+=","+ia[i]
}
}
}
restr = "可以纳橡升被 3,5,7 同时整除的数有:\r\n"+restr
return restr
}
function getLuckNum(luckNum){
var d = {"a":0,"b":0,"c":0}
var re = {"flag":false,"如简msg":"你不够幸运哦 :("}
d.a = "".RandomNumber(1)
d.b = "".RandomNumber(1)
d.c = "".RandomNumber(1)
re.msg = "您获得的3个数字是 :"+d.a+","+d.b+","+d.c
if (d.a == luckNum || d.b == luckNum || d.c == luckNum)
{
re.flag = true
re.msg = re.msg + " 其中包含幸运数字 "+luckNum+" :) 恭喜你了!"
}else{
re.msg = re.msg + " 其中未包含幸运数字 "+luckNum+" :( 继续努力!"
}
return re
}
//--->
</script>
</HEAD>
<BODY>
<TEXTAREA NAME="outText" id="outText" ROWS="15" COLS="40"></TEXTAREA>
<BR>
<input type="button" value="获得被3,5,7整数的数" onclick="document.getElementById('outText').value = getCacNum()">
<input type="button" value="幸运数字8" onclick="alert(getLuckNum(8).msg)">
</BODY>
</HTML>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)