Add sums of array. Display one output

前端 未结 3 410
被撕碎了的回忆
被撕碎了的回忆 2021-01-26 01:02

Update: The answer to this question is bellow. Thanks to dougtesting on a different thread. add array together, display sum

function hello() {
    var arr = [];
         


        
3条回答
  •  清歌不尽
    2021-01-26 01:26

    var arr = [];                               // define our array
    
    for (var i = 0; i < 10; i++) {              // loop 10 times
      arr.push(prompt('Enter number' + (i+1))); // push the value into the array
    }
    
    arr = arr.join(', ');
    alert('Full array: ' + arr);    // alert the result
    
    var arrEquals = []; //Empty array
     arrEquals.push(arr); //assign arr string to an empty array
    
    alert (arrEquals[0]); //show array[0] string to admin for debug
    

    Is this what you are looking for? You need to put the arr.join() result to a variable, like itself.

    You shouldnt be using arr.push() at all if you're not pushing new array items on it

    //(for loop) console out # of  array elements. does not output what is in array
    //this is half the battle  
        for (var a = 0; a < arrEquals.length; a++){
              //a is always a int in this case
               console.log(a + "A"); //used for debug
        }
    

提交回复
热议问题