Wayne
Wayne

Reputation: 143

Displaying result in a table

Good morning all,

I have created a script which i will implement on my site once i have it working ok.

could you please help me out with result.

there is a for loop that does some calculations for me, but the results seem to be on 1 line and not in the vertical column, i cant see where i am going wrong, please help.

var myApp = angular.module('myApp', []);

var startingValue = 3;
var VXP = [2.41, 2.50, 1.80, 1.56, 1.43, 1.35, 1.30, 1.26, 1.23, 1.20, 1.18, 1.17, 1.16, 1.14, 1.13, 1.13, 1.12, 1.11, 1.11, 1.10, 1.10, 1.09, 1.09, 1.08, 1.08];
var text = "";
var i;

for (i = 0; i < VXP.length; i++) {
    startingValue *= VXP[i];
    vxpResult = text += Math.floor(startingValue);
}


function MyCtrl($scope) {
    $scope.level = i;
    $scope.vxp = vxpResult;
}

http://jsfiddle.net/rppge4cm/2/

Upvotes: 2

Views: 46

Answers (1)

dfsq
dfsq

Reputation: 193301

It's because you are concatenating one long string. Try to use array to hold values:

var i;
var vxpResult = [];

for (i = 0; i < VXP.length; i++) {
    startingValue *= VXP[i];
    vxpResult.push(Math.floor(startingValue));
}

function MyCtrl($scope) {
    $scope.level = i;
    $scope.vxp = vxpResult;
}

Demo: http://jsfiddle.net/rppge4cm/3/

Upvotes: 3

Related Questions