1. Apple a 3 yuan, two yuan a pear, a peach one yuan. Now I want to use 200 yuan to buy 100 fruit, print it out in the console.
var apple = 0; //苹果
var pear = 0; //梨
var peach = 0; //桃子
for(apple = 0; apple <= 100; apple++)
{
for(pear = 0; pear <= 100; pear++)
{
for(peach = 0; peach <= 100; peach++)
{
if((apple * 3 + pear * 2 + peach * 1 == 200) && (apple + pear + peach) == 100)
{
console.log(apple, pear, peach);
}
}
}
}
2. Calculate the sum of the parity (0-100
var n = 0;
was num1 = 0;
for(var i=1;i<=100;i++){
if(i%2==0){
Surely + = i;
}else{
num1+=i;
}
}
document.write ( "sum is an even number:" + num, "the sum is odd:" + num1);
3. Print the multiplication table (which may be in the loop for the variable var i = 1 is proposed to write)
for(var i=1;i<10;i++){
for(var j=1;j<10;i++){
document.write(i+"*"+j+"="+i*j+" ")
if(i=j){
document.write("<br/>");break;
}
}
}
4. Enter a four-digit, display bits, ten, one hundred, one thousand of the console are values
var a = prompt ( "Please enter a four-digit positive integer");
var B = the parseInt (A / 1000);
var C = the parseInt (A / 100);
var D = 10% C;
var E A = 100%;
var F = the parseInt (E / 10);
var G A = 10%;
the console.log ( ' is the thousand: '+ b,' hundreds digit is: '+ d,' tens digit is: '+ f,' digits are: '+ g);
The determined prime number within 1-100
var i = 0;
var j = 0;
for(i = 1; i <= 100; i++)
{
var count = 0;
for(j = 1; j <= i; j++)
{
if(i % j == 0)
{
count++;
}
}
if(count == 2)
{
console.log(i);
}
}
6. supermarket discount of twenty percent
var money = prompt ( "Enter amount");
if(!isNaN(money) && money>=100){
money=money*0.8;
console.log(money);
}else{
console.log(money)
}
7. Print right triangle
var num = prompt ( "Please enter the number of lines");
for (var i = 0; i <= num; i ++) {
document.write("*");
for(var j=1;j<=i;j++){
document.write("*");
}
document.write("</br>");
}
8. Calculate 1 + 2 + 3 + 4 + 5 + ...... + 10;
var a =1;
var num = 0;
for(a = 1; a <=10; a = a + 1){
num = num + a;
};
console.log(num);
9. Enter a number determined is prime
var i = prompt ( 'Enter a not less than two positive integers');
var COUNT =. 1;
for (NUM = 2; NUM <= I; NUM ++) {
IF (I% == 0 NUM) {
COUNT = COUNT + 1'd;
}
}
IF (COUNT == 2) {
Alert ( 'the number is prime number ");
}
the else {
Alert (' this is not a prime number");
}
10.计算6+66+666+....+6666666666
var i = 0;
var sum =0;
var n =0;
for(i = 1; i <=10; i++){
n = 6 + n*10;
sum = sum + n;
}
console.log(sum);