JS Built-in Object Processing _ print student transcripts simple to achieve _javascript skills

Source: Internet
Author: User

Task:

1. Get the current date through the built-in object of JS

var date=new date ();

var year=date.tostring (). Slice (11,15);
document.write (year.tostring () + "year");

var month=date.getmonth ();
month=month+1;
if (month<10) {

document.write ("0" +month+ "month");
} else{
document.write (month+ "Month"); 
}

var day=date.tostring (). Slice (8,10);
document.write (day+ "Day");

var weekday=["Day", "one", "two", "three", "four", "five", "six"];
var week=date.getday ();
document.write ("Week" +weekday[week]);

2. Better operation of the string in an array

var scorestr = "Xiao Ming: 87; Floret: 81; Xiao Hong: 97; Little day: 76; little Zhang: 74; small: 94; Xiao XI: 90; Xiao Wu: 76; Dicky: 64; Xiaoman:";
var scorearr=scorestr.split (";");

3. Rub the score out of the array, sum the whole and output

function Getnum (str) {
var str1=str.replace (/[*0-9]/ig, "");
Return Str.replace (STR1, "");
}

 

var num=0, Len=scorearr.length;
for (Var i=0;i<len;i++) {
var num1=getnum (Scorearr[i]);
Num+=number (NUM1);
}
Num=parseint (Num/len);
document.write ("--the average class is divided into:" +num);

Here's my chart of effects:

The above is small series for everyone to bring the JS built-in object processing _ print student transcript of the simple realization of all the content, hope to help you, a lot of support cloud Habitat Community ~

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.