Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This question was closed Jun 02, 2011 at 02:00 PM by Eric5h5 for the following reason:

Off-topic

avatar image
0
Question by dobby · Jun 02, 2011 at 10:40 AM · off-topic

JavaScript

Hi i wonder if anyone can help, I'm trying to write a program in JS to add the elements of two arrays together - ie firstArray = [1,2,3,4,5,6,7,8,9] secondArray = [2,3,4,5,6,7,8,9,10]...........I need to know how to add the first element in firstArray to the first element in secondArray and display the result.

I have the data in the arrays already and have writen this:-

 var onlineVotesArray = new Array (41,37,43,11,59,21,36);
 var paperVotesArray = new Array (22,3,15,11,7,1,10);
 var candidateArray = new Array ("Mrs J Smith", " Mrs H J Rowe", " Ms Brown", " A N Other"," Mr White"," Ms I M Blue", " Mr P D Jones");
 var totalVotesArray = new Array ();
     for (i = 0, l = candidateArray.length; i < l; i++)
     {
     document.write(candidateArray[i] + ' has ' + onlineVotesArray[i] + ' Online votes and ' + 
     paperVotesArray[i] + ' Paper votes giving them a total of ' + ' votes.' +'<BR>');
     }
     document.write('<BR>');

but I do not know how to add the elements together, I thought of putting:- totalVotesArray = ((onlineVotesArray) + (paperVotesArray)); but that does not work - help please!

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Wolfram · Jun 02, 2011 at 10:55 AM 0
Share

This doesn't appear to be a Unity question, so next time I suggest asking it at http://stackoverflow.com/ which has the additional advantage of being a much larger community, so it is more likely you'll get more/quicker/better answers

1 Reply

  • Sort: 
avatar image
0

Answer by Wolfram · Jun 02, 2011 at 10:51 AM

Before your for-loop initialize the array to have the correct size:

 totalVotesArray.length=candidateArray.length;

In your for-loop just add the arrays on a per-element-basis:

 totalVotesArray[i]=onlineVotesArray[i]+paperVotesArray[i];
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

From C# to C for the S2 game engine 4 Answers

unity web player startup 0 Answers

blender tutorials 1 Answer

Why is Unity so great? 2 Answers

Problems with Webplayer 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges