JS extracts numbers from an array

Source: Internet
Author: User
Tags ming ord

A class of results come out, now the teacher to the class of results printed out.

:

XXXX year XX month x Day week x--class Total is divided into: 81

Format requirements:

1. Display the date of printing. The format is similar to the current time of "xxxx year XX month XX day week X".

2. Calculate the average (reserved integer) of the class.

Student performance data are as follows:

"Xiao Ming: 87; Floret: 81; Little Red: 97; Small day: 76; Xiao Zhang: 74; little: 94; Xiao XI: 90; Xiao Wu: 76; Dicky: 64; Small ord: 76 "

Task

The first step: you can get the current date by using JavaScript's Date object.

Tip: Use Date () Dates object, note that the week return value is 0-6, so you want to turn the word "Week X"

The second step: a long-channeling string is not good, find the rule after the division into the array to better operate OH.

Step three: Divide the string to get the score, then sum the rounding.

Tip: The parseint () string type is converted to an integral type.

<! DOCTYPE html>//get the current date by using the JavaScript Date object and output.   varMydate=NewDate (); //The result is a long-channeling string bad processing, find the rule after the split into the array better operation Oh  varScorestr = "Xiao Ming: 87; Floret: 81; Little red: 97; Small day: 76; Xiao Zhang: 74; little: 94; Xiao XI: 90; Xiao Wu: 76; Dicky: 64; Small ord: 76"; varArr=scorestr.split (': ')); //Extract the scores from the array, then sum them up and output them.   varSum=0;  for(vari=0;i<arr.length;i++)  {      if(i%2) {sum+=parseint (Arr[i]); document.write (parseint (arr[i])+ "<br>");  }} document.write (sum); </script>

JS extracts numbers from an array

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.