Advertisement
Guest User

PricesTrendsTable

a guest
Jul 30th, 2014
360
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. function prices(input) {
  2. var numbers = input[0].split(/[ ]+/);
  3. var nums = new Array();
  4.  
  5. for (var i = 0; i < numbers.length; i++) {
  6. nums.push(parseFloat(numbers[i]).toFixed(2));
  7.  
  8. }
  9.  
  10. console.log("<table>");
  11. console.log("<tr><th>Price</th><th>Trend</th></tr>");
  12. console.log("<tr><td>" + nums[0] + '</td><td><img src="fixed.png"/></td></td>');
  13. for (var j = 0; j <= nums.length-1; j++) {
  14.  
  15.  
  16. if (nums[j] < nums[j+1]){
  17. console.log("<tr><td>" + nums[j+1] + '</td><td><img src="up.png"/></td></td>');
  18. }
  19. if (nums[j] > nums[j+1]) {
  20. console.log("<tr><td>" + nums[j+1] + '</td><td><img src="down.png"/></td></td>');
  21. }
  22. if (nums[j] == nums[j+1]) {
  23. console.log("<tr><td>" + nums[j+1] + '</td><td><img src="fixed.png"/></td></td>');
  24. }
  25.  
  26. }
  27. console.log("</table>");
  28. }
  29.  
  30. prices(['36.333 36.5 37.019 35.4 35 35.001 36.225']);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement