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>