Guest User

Untitled

a guest
Mar 9th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. 'use strict' ;
  2.  
  3.  
  4. // 1. Create a function that takes a parameter and returns the parameter's data type
  5. function dataType(data){
  6. return typeof data;
  7. }
  8. dataType(false);
  9. dataType(7);
  10. dataType('this is a string');
  11.  
  12.  
  13.  
  14. // 2. Create two person objects. Both must have 6 properties: name, username, password,
  15. // age, salary, occupation, and location. Create a function that will take an object as
  16. // an argument and returns 'You may enter' if the username is 'tstark' and the password
  17. // is 'ironman447'.
  18.  
  19. var personOne = {
  20.  
  21. name: 'Ahmed' ,
  22. username: 'Ahmed177',
  23. password:'coolguy123',
  24. age: 18 ,
  25. salary: 20000,
  26. occupation: 'dispatcher',
  27. location: 'Seattle'
  28. }
  29.  
  30. var personTwo = {
  31.  
  32. name: 'Tony' ,
  33. username: 'tstark' ,
  34. password: 'ironman447' ,
  35. age: 28 ,
  36. salary: 300000,
  37. occupation: 'superhero',
  38. location: 'Not seattle'
  39.  
  40. }
  41.  
  42. function login( obj ){
  43.  
  44. if ( obj.username === 'tstark' && obj.password === 'ironman447') {
  45. return 'You may enter';
  46. } else{
  47. return 'Access denied';
  48. }
  49. }
  50.  
  51. login(personOne);
  52. login(personTwo);
  53.  
  54. // 3. Create another function that takes an object as an argument and alerts the object's location.
  55.  
  56. function alertLocation( obj ){
  57. alert('Location: ' + obj.location) ;
  58. }
  59.  
  60. alertLocation(personOne);
  61. alertLocation(personTwo);
  62.  
  63. // 4. Create another function that takes an object as an argument and alerts 'Become a developer'
  64. // if the age is 18 or older, salary is less than $60,000, and occupation is not 'developer'.
  65.  
  66. function becomeDeveloper(obj){
  67. if (
  68. obj.age >= 18 ;
  69. obj.salary < 60000 ;
  70. obj.occupation != developer ;
  71. ) {
  72. alert('Become a developer') ;
  73. } else{
  74. alert('Sorry buddy, not for you.');
  75. }
  76.  
  77. }
  78.  
  79. becomeDeveloper(personOne);
  80. becomeDeveloper(personTwo);
Add Comment
Please, Sign In to add comment