Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1. )
- String, Boolean, Numbers and Float
- 2. )
- `Math.sqrt(9);`
- 3. )
- `Math.round(2.5);`
- 4.)
- `x = "hello", y = x.charAt (3,4) = "lo"` : Choosing a specific value range on string.
- `x = "hello", y = y.startswith ("h") = true` : Choose if a string starts with a specific value.
- `x = [h,e,l,l,o], x.push ("l") = x = [h,e,l,l,o,l]` : adding value to end of array.
- `x = [h,e,l,l,o], y=x.join ["hello"]`: joining all values in an Array to form a string.
- 5. )
- undefined is when the datatype has not been fixed. null is the default for datatypes.
- Bonus
- JS Part II
- 1.)
- `x.shift()`
- 2.)
- 'x.pop()'
- 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.
- //example
- var x = [8,4,3,9,0,1,4];
- //the expression you write will return 9 in this case
- 3.)
- ```
- var x = [8,4,3,9,0,1,4];
- var middle = x[Math.floor((x.length - 1) / 2)];
- console.log(middle);
- ```
- 4. )
- While will execute code as long as test is true. Do-while will do the same after executing the code once.
- 5. )
- ```
- var array = "h,e,l,l,o, ,w,o,r,l,d".split(',');
- var i = 0;
- while (i < array.length) {
- i += i;
- var t = array[i-1];
- array[i-1] = array[i];
- array[i] = t;
- }
- ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement