本文目录一览:
- 1、js少儿编程这道题怎么做啊
- 2、JavaScript的两道编程题有大佬会吗?感激不尽!
- 3、js做一些编程题。
- 4、js编程,这道题怎么做?专业的请进
- 5、这道JS题怎么做?计算n到m之间所有整数的和(要求如下,急,谢谢)
- 6、面试 | JS 异步编程经典面试题
js少儿编程这道题怎么做啊
html
script type="text/javascript"
function F()
{
//保存为.htm文件
var randomArr=[];
for(var i=0;i100;i++)
{
randomArr[i]=parseInt(Math.random()*(200-100)+1)+100;
randomArr[i]+=1;
document.write(""+randomArr[i]+"br /");
}
}
F();
/script
/html
JavaScript的两道编程题有大佬会吗?感激不尽!
!DOCTYPE html
html lang="en"
head
meta charset="UTF-8"
titleTitle/title
/head
body
/body
form
div
h11/h1
!--
1.JavaScript编程编程计算1+1/2+1/3+…+1/n的和。按下图页面效果,编程实现所需功能。
(1)使用循环结构进行编程,形式不限;
(2)通过表单中文本输入框输入数n,n不能为空或null;
(3)表单中添加2个文本输入框,用于输入数n和显示累加和;添加1个普通按钮和重置按钮。
(3)单击“计算倒数的和”按钮,可以通过函数sum()将计算结果回填到累加和文本输入框中,计算结果保留2位小数。
--
label输入数N: /labelinput type="number" id="n"br/
label累加和: /labelinput type="number" id="result"br/
button type="button" onclick="sum()"计算倒数的和/button
button type="reset"重置/button
/div
hr/
div
h12/h1
!--
2、JavaScript编程编程实现计算n个随机3位数的和,如下图所示。
(1)在body标记中通过提示框输入数N;
(2)编写computer_sum(num)函数。采用do while循环结构实现计算num个随机3位整数的和;用随机函数产生随机的3位正整数,并逐个输出到页面上;
(4)将计算结果直到输出在页面上。
--
label id="result2"/label
/div
/form
script
// 1
function sum(){
var nInput = document.getElementById("n")
var resultInput = document.getElementById("result")
var n = nInput.value
var sum = 0
for(var i=1;i=n;i++){
sum+=(1/i)
}
sum = Math.round(sum*100)/100
resultInput.value = sum
}
// 2
computer_sum(prompt('输入数N:'))
function computer_sum(n){
var sum = 0
var numbers = []
var i=0
do {
var num = Math.round(Math.random()*900+100) // 生成一个3位随机数
sum+=num
numbers.push(num)
i++
} while(in)
var outputStr = n+"个3位随机数: "+ numbers.join(" ")+"br/"+n+"个3位随机数之和="+sum
document.getElementById("result2").innerHTML = outputStr
}
/script
/html
js做一些编程题。
//1.
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);
js编程,这道题怎么做?专业的请进
谁说要很长时间的??瞎扯淡蛋。
!DOCTYPE HTML
html
meta charset="UTF-8" /
head
titleYuGiOh Power Of Chaos/title
style type="text/css"
/style
script type="text/javascript" src="jquery-1.8.0.min.js"/script
script type="text/javascript"
var Card = function (suit, face)
{
this.suit = suit;
this.face = face;
};
Card.prototype = new Card;
Card.prototype.constructor = Card;
Card.prototype.setSuit = function (suit)
{
this.suit = suit;
};
Card.prototype.setFace = function (face)
{
this.face = face;
};
Card.prototype.toString = function ()
{
return "suit = " + this.suit + ", face = " + this.face;
}
Card.prototype.shuffle = function ()
{
var s = "方块,红心,黑桃,梅花";
var f = "A,1,2,3,4,5,6,7,8,9,10,J,Q,K,王";
var ss = s.split (/\,/), fs = f.split (/\,/);
this.suit = ss[Math.floor (Math.random () * ss.length)];
this.face = fs[Math.floor (Math.random () * fs.length)];
};
Date.prototype.getYesterday = function ()
{
var now = new Date;
now.setDate (now.getDate () - 1);
return now;
};
var card = new Card ();
card.setSuit ("红心");
card.setFace ("A");
console.log (card.toString ());
card.shuffle ();
console.info (card.toString ());
var yesterday = new Date ().getYesterday ();
console.debug (yesterday);
/script
/head
body
/body
/html
这道JS题怎么做?计算n到m之间所有整数的和(要求如下,急,谢谢)
!DOCTYPE html
html
head
meta charset="UTF-8" /
meta name="viewport" content="width=device-width, initial-scale=1.0" /
meta http-equiv="X-UA-Compatible" content="ie=edge" /
titleDocument/title
/head
body
/body
script
let sum = (n, m) = n == m ? n : n + sum(++n, m)
alert(sum(10, 100))
/script
/html
请采纳
面试 | JS 异步编程经典面试题
先来看一个小例子
再来看一个小栗子
.then()/.catch() 中的返回值都不能是 promise 自己本身的实例,因为会造成死循环
先来看一个栗子
Promise 必知必会(十道题)
BAT前端经典面试问题:史上最最最详细的手写Promise教程
MDN async/await