The first stage test problem finishing (bubble sort, go heavy, perpetual calendar) and change the wrong--2017-03-26

Source: Internet
Author: User

1, Bubble sorting method: five-star focus

<script>
var arr=array ();
for (Var i=0;i<=5;i++) {
var j=prompt ("Please enter the number of +i+");
J=parseint (j);
Arr.push (j);
}
for (Var x=0;x<arr.length;x++) {
for (Var y=x+1;y<arr.length;y++) {
if (Arr[x]<arr[y]) {
var temp=arr[x]; ------Core
Arr[x]=arr[y];
Arr[y]=temp;
}
}

document.write (arr[x]); --------This step does not require the following traversal output (concise)
}
For (var k in arr) {
document.write (Arr[k]);
}
</script>

2, go to weight: also important, principle

<script>
var attr=[1,1,2,3,4,4,4,5,6,6,6,6];
var arr=array ();
for (var x=0; X<attr.length; x + +) {//when x<=attr.length, the result output 123456undefined, the reason to see below
var status=0;
for (var y=x+1; Y<attr.length; y++) {//when y<=attr.length, result output 123456undefined
if (Attr[x]==attr[y]) {
Status=1;
Continue
}
}
if (status==0) {
Arr.push (Attr[x]);
}
}
for (Var z in arr) {
document.write (Arr[z]);
}
</script>

Cause: At the same time output 123456 more output undefined---undefined means to occupy a bit but the missing value. So x does not need to be the last cycle, can be x<=attr.length-1; or can be removed.

Exam Deduction Reason:

The de-weight is not compared with the neighboring numbers; the first number is more than the rest of the number, and the second number is compared to every other!!!!!

3. Perpetual calendar

Refer to the dynamic clock written in 2017-03-23

Note the point:

(1) d.getmonth ()+1; ------------Month to add 1, you forget the exam!!!!

(2) d.gethours (); -------------These three are plural forms ...

D.getminutes ();

D.getseconds ();

(3) SetInterval ("Show ()", 1000); -----------Set the time interval, because you want to dynamically display

4. Change the error :

(1) subdtring (A, a)------a refers to the starting position; B refers to the end position; The index value, that is, the 0-based number!!!!!

(2) "Var x=0; while (); x+=2; " Then if you make the while through the bad body 10 times, the parentheses should be filled _x<=18_ or x<=19 or _x<19 or x<20__

I filled it with x<=9;. do wrong reason : examining not careful, think x+=1!!!!!!

The first stage test problem finishing (bubble sort, go heavy, perpetual calendar) and change the wrong--2017-03-26

Related Article

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.