Advertisement
Guest User

tableBuilder

a guest
Nov 12th, 2014
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. function buildTable(arr){
  2. var start = arr[0];
  3. var end = arr[1];
  4.  
  5. console.log("<table>")
  6. console.log("<tr><th>Num</th><th>Square</th><th>Fib</th></tr>")
  7.  
  8. function fibChecker(num){
  9. var firstNum = 0;
  10. var secondNum = 1;
  11. var fibNum = firstNum + secondNum;
  12. var isFib;
  13.  
  14. while(fibNum <= num){
  15. if(fibNum == num){
  16. isFib = 'yes';
  17. break;
  18. } else{
  19. firstNum = secondNum;
  20. secondNum = fibNum;
  21. fibNum = firstNum + secondNum;
  22. isFib = 'no';
  23. }
  24. }
  25. return(isFib);
  26.  
  27. }
  28.  
  29. for(var i = start; i <= end; i++){
  30. console.log("<tr><td>" + i + "</td><td>" + i*i + "</td><td>" + fibChecker(i) + "</td></tr>")
  31. }
  32. console.log('</table>')
  33.  
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement