JS Introduction, how to quickly cooked JS. Lay a solid foundation.

Source: Internet
Author: User

JS determines the behavior of the Web page, there is the logic of behavior, and the computer is just artificial intelligence, you give it what kind of instructions, it will follow your instructions to run.

Some people would ask, since it is given instructions, what logic does it need?

Here I give a simple small example to illustrate!

What do you do if you want to enter a score and let the print table print out the grades?

Rank Rule 90<= Score <100 system print a,80<= score <90 print b,70<= score <80 print c,60<= score <70 print d,60>= print E

At this point, you need to give instructions, then what kind of instructions are required?

I'm going to write the code to explain

var x=prompt (' Input score ')


if (x>=90&&x<=100) {
Console.log (' A ');
}
else if (x>=80)
{
Console.log (' B ');
}
else if (x>=70) {
Console.log (' C ');
}
else if (x>=60)
{
Onsole.log (' D ');
}
else if (x>=0)
{
Console.log (' E ');
}
var x<=100;

Here we will use if and var.

If in JS is the meaning of judgment. and Var is the meaning of defining a variable.

First Look at Var x=prompt (' Input score ');

In this sentence, we define the variable x, and then enter a score within the output box.

So what do we need to do to get the results out? What other people input is the result, I certainly will not know! So we need to judge the result.

Then we need to use the If judgment.

if (90<x<100) {
 
}
else{

The x>=90&&x<=100 inside the IF parenthesis is the condition we need to judge.

What do you do with the {} behind him? With the condition of judgment, then of course there will be a situation satisfying it and not satisfying it!

Immediately after that, the {} is the next thing he needs to do when judging the score X satisfies the condition.

So we write Console.log (' A ') in {};

At this point, when you enter a number greater than 90 and less than 100 in prompt (' input score '), the Console.log will print a.

So

if (90<x<100) {
 
}
else{

The first {} in the} knows what it is, and what's behind it?

Yes, that's what you need to get the computer to do when the if Judge is no.

What is the case if the judgment is no? Of course, the output score is not between 90 and 100.

This is going to get into the else. So what does it take to get into the else? Then we need to continue to judge.

if (x>=90&&x<=100) {
Console.log (' A ');
}
else if (x>=80)
{
Console.log (' B ');
}
Notice that there is another if after else, what does that mean? That is, when the first if is judged to be no, I make a judgment.

See here, do not know that people understand No.

This is a simple logical question.

and want to learn JS, for JS to lay a solid foundation, you need to learn more logic knowledge. Can be fearless js a lot of problems.

JS Introduction, how to quickly cooked JS. Lay a solid foundation.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.