Advertisement
Guest User

Untitled

a guest
May 26th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. 1. )
  2. String, Boolean, Numbers and Float
  3.  
  4. 2. )
  5. `Math.sqrt(9);`
  6.  
  7. 3. )
  8. `Math.round(2.5);`
  9.  
  10. 4.)
  11. `x = "hello", y = x.charAt (3,4) = "lo"` : Choosing a specific value range on string.
  12. `x = "hello", y = y.startswith ("h") = true` : Choose if a string starts with a specific value.
  13.  
  14. `x = [h,e,l,l,o], x.push ("l") = x = [h,e,l,l,o,l]` : adding value to end of array.
  15. `x = [h,e,l,l,o], y=x.join ["hello"]`: joining all values in an Array to form a string.
  16.  
  17. 5. )
  18. undefined is when the datatype has not been fixed. null is the default for datatypes.
  19. Bonus
  20.  
  21. JS Part II
  22. 1.)
  23. `x.shift()`
  24.  
  25. 2.)
  26. 'x.pop()'
  27. Assume array x contains an odd number of elements (i.e. its length is an odd number). Write an expression that returns the MIDDLE element of the array.
  28.  
  29. //example
  30. var x = [8,4,3,9,0,1,4];
  31. //the expression you write will return 9 in this case
  32. 3.)
  33. ```
  34. var x = [8,4,3,9,0,1,4];
  35. var middle = x[Math.floor((x.length - 1) / 2)];
  36. console.log(middle);
  37. ```
  38. 4. )
  39. While will execute code as long as test is true. Do-while will do the same after executing the code once.
  40.  
  41.  
  42. 5. )
  43. ```
  44. var array = "h,e,l,l,o, ,w,o,r,l,d".split(',');
  45. var i = 0;
  46. while (i < array.length) {
  47. i += i;
  48. var t = array[i-1];
  49. array[i-1] = array[i];
  50. array[i] = t;
  51. }
  52. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement