Guest User

Untitled

a guest
Mar 11th, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. //1. Create a function that takes a parameter and returns the parameter's data type
  2. function dataType(data){
  3. return typeof data;
  4. }
  5. dataType(12);
  6. dataType('Hello');
  7.  
  8. /*2. Create two person objects. Both must have 6 properties: name,
  9. username, password, age, salary, occupation, and location.
  10. Create a function that will take an object as an argument and
  11. returns 'You may enter' if the username is 'tstark' and the password is 'ironman447'.
  12. */
  13. person1 = {
  14. name: 'Bruce Wayne',
  15. username: 'bwayne',
  16. password: 'batman123',
  17. age: 52,
  18. salary: 20000,
  19. occupation: 'actor',
  20. location: 'USA'
  21. }
  22.  
  23. person2 = {
  24. name: 'Tony Stark',
  25. username: 'tstark',
  26. password: 'ironman447',
  27. age: 47,
  28. salary: 1000000,
  29. occupation: 'actor',
  30. location: 'America'
  31. }
  32.  
  33. function login (obj){
  34. if (obj.username === 'tstark' && obj.password === 'ironman447')
  35. return ('You may enter');
  36. }
  37. login(person2);
  38.  
  39. /*
  40. 3. Create another function that takes an object as
  41. an argument and alerts the object's location.
  42. */
  43. function alertLocation(obj) {
  44. alert(obj.location);
  45. }
  46. alertLocation(person2);
  47.  
  48. /*
  49. 4. Create another function that takes an object as an argument and
  50. alerts 'Become a developer' if the age is 18 or older, salary is less
  51. than $60,000, and occupation is not 'developer'.
  52. */
  53.  
  54. function programmer (obj){
  55. if (obj.age>=18 && obj.salary <60000 && obj.occupation!='developer') {
  56. alert('Become a developer!');
  57. } else {
  58. alert('Keep it up!');
  59. }
  60. }
  61. programmer(person1); // Become a developer
  62. programmer(person2); // Keep it up!
Add Comment
Please, Sign In to add comment