Advertisement
lemansky

Untitled

Feb 17th, 2021
728
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // index.js
  2. const task1 = (size) => {
  3.     for (let index = 0; index <= size; index++) {
  4.         console.log(index);
  5.     }
  6. }
  7.  
  8. // task1(10);
  9.  
  10. const task2 = () => {
  11.     let _printNums = "";
  12.     for (let index = 10; index >= 0; index--) {
  13.         _printNums += index + " ";
  14.     }
  15.     console.log(_printNums);
  16. }
  17.  
  18. // task2();
  19.  
  20. const task3 = (wordOne, wordTwo) => {
  21.     if(wordOne.length > wordTwo.length){
  22.         console.log(`${wordOne} is longer.`);
  23.     } else if(wordOne.length < wordTwo.length){
  24.         console.log(`${wordTwo} is longer.`);
  25.     } else {
  26.         console.log(`${wordOne} is the same length as ${wordTwo}`);
  27.     }
  28. }
  29.  
  30. // task3("Ruby", "Java");
  31.  
  32. const task4 = (num) => {
  33.     num += "";
  34.     for (let index = 0; index < num.length; index++) {
  35.         console.log(num[index]);
  36.     }
  37. }
  38.  
  39. // task4(15898);
  40.  
  41. const task5 = (num) => {
  42.     for (let index = 1; index < num; index = index * 2) {
  43.         if(num >= index*2)
  44.         console.log(index*2);
  45.     }
  46. }
  47.  
  48. // task5(33);
  49.  
  50. const task6 = (stringNums) => {
  51.     let _arrNums = stringNums.split(", ");
  52.     console.log(_arrNums);
  53.     let _sumNums = 0;
  54.     for (let index = 0; index < _arrNums.length; index++) {
  55.         _sumNums += +_arrNums[index];
  56.     }
  57.     console.log(_sumNums);
  58. }
  59.  
  60. // task6("1, 4, 5, 7");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement