Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. # JS | Functions
  2.  
  3. <br>
  4.  
  5. ## Syntax - Exercise
  6.  
  7.  
  8. Let's practice the function syntax:
  9.  
  10. <br>
  11.  
  12. **Task 1**
  13.  
  14. Create function called `fullName` using *function declaration* syntax.
  15.  
  16. The function should take 2 arguments, `firstName` and `lastName` and `return` a new string representing the full name.
  17.  
  18.  
  19.  
  20. ```js
  21. // Your code here
  22.  
  23. console.log( fullName('Bob', 'Smith') ); // expected: Bob Smith
  24. ```
  25.  
  26.  
  27.  
  28. <br>
  29.  
  30.  
  31.  
  32. **Task 2**
  33.  
  34. Create the same function as a function expression, but this time name it `fullNameExpr`.
  35.  
  36. ```js
  37. // Your code here
  38.  
  39. console.log( fullNameExpr('Sarah', 'O\'Connor') ); // expected: Sarah O'Connor
  40. ```
  41.  
  42.  
  43.  
  44. <br>
  45.  
  46.  
  47.  
  48. **Task 3**
  49.  
  50. Create the same as arrow function, but this time name it `fullNameArrow`.
  51.  
  52. ```js
  53. // Your code here
  54.  
  55. console.log( fullNameArrow('Axel', 'Garcia') ); // expected: Axel Garcia
  56. ```
  57.  
  58.  
  59.  
  60. <br>
  61.  
  62.  
  63.  
  64. **Bonus** -
  65.  
  66. Create the same function as concise arrow function.
  67.  
  68. ```js
  69. // Your code here
  70.  
  71. console.log( fullNameArrow('Esther', 'Bernal') ); // expected: Esther bernal
  72. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement