Advertisement
Guest User

Untitled

a guest
Apr 27th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. // This function solves the Marco Polo Problem
  2. // Input is number till which you want to print values
  3. // Returns a single string which performs thee logic of Marco Polo.
  4. function marcoPoloFunc(number){
  5. var retVal='';
  6. for(var i=1; i<=number;i++){
  7. if(i%4==0 && i%7==0) // checks if number is divisible by both 4 and 7
  8. retVal+='marcopolo'
  9. else if(i%4==0) // checks if number is divisible by 4
  10. retVal+='marco'
  11. else if(i%7==0) // checks if number is divisible by 7
  12. retVal+='polo'
  13. else
  14. retVal+=i;
  15. retVal+=',';
  16. }
  17. retVal =retVal.substring(0,retVal.length-1);
  18. console.log(retVal); // print to console.
  19. return retVal; // returns the single string with required output
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement