JavaScript programming question (1): javascript programming question

Source: Internet
Author: User

JavaScript programming question (1): javascript programming question

Use document. write () to output a horizontal line

Use loops to control the length of each horizontal line

Answer: <! Doctype html>

<Head>

<Meta charset = "UTF-8">

<Meta name = "Generator" content = "EditPlus®">

<Meta name = "Author" content = "">

<Meta name = "Keywords" content = "">

<Meta name = "Description" content = "">

<Title> Document </title>

</Head>

<Body> <script type = "text/javascript">

Var n = window. prompt ("number of rows in the input print pyramid ");

For (var I = 0; I <= n; I ++ ){

For (var j = I; j <= n-1; j ++ ){

Document. write ("______");

}

Document. write ("<br/> ");

} For (var I = 0; I <= n; I ++ ){

For (var j = 0; j <= I-1; j ++ ){

Document. write ("______");

}

Document. write ("<br/> ");

}

</Script>

</Body>

</Html>

2. Use javascript scripts to output squares on the page. The requirements are as follows.

() Use the prompt () method to input the number of rows of a square.

(2) No matter whether the number of rows of the input square is greater than 10, the output square can be up to 10 rows.

Page effect:

Tip:

Declare a variable num to save the prompt () method to obtain the number of input rows.

Use if to determine if num is greater than 10. if num is greater than 10, assign the value num = 10,

You can use a double loop to display the square, the number of lines in the outer layer, and the number of # numbers in each line in the inner layer"

Answer:

<! Doctype html>

<Html lang = "en">

<Head>

<Meta charset = "UTF-8">

<Meta name = "Generator" content = "EditPlus®">

<Meta name = "Author" content = "">

<Meta name = "Keywords" content = "">

<Meta name = "Description" content = "">

<Title> Document </title>

 

</Head>

<Body> <script type = "text/javascript">

Var n = window. prompt ("Enter the number of square rows :","");

For (var I = 0; I <= n-1; I ++ ){

For (var j = 0; j <= n-1; j ++ ){

If (n> 10 ){

N = 10

Document. write ("& nbsp; # & nbsp ;");

 

} Else {

Document. write ("& nbsp; # & nbsp ;");

 

}

 

}

Document. write ("<br/> ");}

 

</Script>

</Body>

</Html>

3. Use the prompt () method to bring up a prompt on the page. Different information is displayed based on the type of the day that each user inputs on the same day of the week. The requirements are as follows.

Enter a day of the week to pop up "the new week has started"

Enter "study hard" on Tuesday, Wednesday, and Thursday !!"

Enter "Tomorrow is the weekend" on Friday"

"Relax" is displayed when other content is entered"

Effect

 

Answer:

 

<! Doctype html>

<Html lang = "en">

<Head>

<Meta charset = "UTF-8">

<Meta name = "Generator" content = "EditPlus®">

<Meta name = "Author" content = "">

<Meta name = "Keywords" content = "">

<Meta name = "Description" content = "">

<Title> Document </title>

</Head>

<Body> <script type = "text/javascript">

Var n = window. prompt ("Enter the day of the week :");

Switch (n) {case "Monday": window. alert ("the start of the new week"); break;

 

Case "Tuesday": window. alert ("study hard !! "); Break;

 

Case "Wednesday": window. alert ("study hard !! "); Break;

 

Case "Thursday": window. alert ("study hard !! "); Break;

 

Case "Friday": window. alert ("Tomorrow is the weekend"); break;

 

Case "Saturday": window. alert ("relax"); break;

 

Case "Sunday": window. alert ("relax"); break;

 

Default: window. alert ("the input week is incorrect! "); Break;

 

 

 

}

</Script>

</Body>

</Html>

 

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.