Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
481 views
in Technique[技术] by (71.8m points)

javascript - Javascript-新手和挣扎(Javascript - newbie and struggling)

I am brand new to learning to code and I am struggling with the basics.

(我对学习编码是全新的,并且我在基础方面苦苦挣扎。)

In javascript, I am trying to write a while loop that runs up to 20 times, it prints "Julia" if the number is divisible by 3, it prints "James" if the number is divisible by 5, and it prints "JuliaJames" if the number is not divisible by 3 or 5.

(在javascript中,我试图编写一个while循环,该循环最多运行20次,如果该数字可被3整除,则将打印“ Julia”;如果将数字可被5整除,则将打印“ James”,然后将其打印“ JuliaJames”如果数字不能被3或5整除。)

Here is what I have:

(这是我所拥有的:)

var x = 10;

while ( x < 20) {
    if  ( x % 3 === 0) {
        console.log ("Julia");
    }
    else if (x % 5 === 0) {
        console.log ("James");
    }
    else {
        console.log ("JuliaJames");
    }
}

I think the problem is that I have not identified how to increment x.

(我认为问题是我尚未确定如何递增x。)

I tried a couple of different places - after the "else, and before the "if" (but that doesnt make any sense).

(我尝试了几个不同的地方-在“其他”之后和“ if”之前(但这没有任何意义)。)

Can someone throw me a bone?

(有人可以给我扔骨头吗?)

Cheers.

(干杯。)

  ask by KellyJenkins translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

while循环的底部,添加x = x + 1或简称x++


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...