for( n=1; n<100; n++){ if(n%7==0 || n%10==7 || parseInt(n/10)==7){ console.log(n); } }
100内与7相关的数:被7整除,个位有7,十位有7; 使用,分隔
for (n = 2; n < 100; n++) { var iszhi = true; for (var m = 2; m < n; m++) { if (n % m == 0) { iszhi = false; } } if (iszhi) { console.log(n); } }
三、九九乘法表
for( i=1; i<10;i++){ for( j=1;j<=i;j++){ var msg = j + ‘*‘ + i + ‘=‘ + j * i + ‘ ‘ document.write(msg) } document.write(‘<br>‘) }
四、100元购物卡,牙刷5元,香皂2元、洗发水15元 100元正好花完有多少种可能
var k = 0; for(x=0;x<=20;x++){ for(y=0;y<=50;y++){ for(z=0;z<=6;z++){ if(5*x+2*y+z*15==100){ // console.log(x+‘,‘+y+‘,‘+z+‘,‘) k++; } } } } console.log(k);
function a(n){ if(n==1){ return 1; }else if(n==2){ return 2; }else{ return a(n-1)+a(n-2); } } var m = a(10); console.log(m);
var cp = prompt(); var arr = []; while(true){ var red = parseInt(Math.random()*33)+1; var isok = arr.indexOf(red); if(isok==-1){ arr.push(red); } if(arr.length == 6) break; } var blue = parseInt(Math.random()*16)+1; arr.push(blue); console.log(arr);
原文:https://www.cnblogs.com/xy19961213/p/14801940.html