Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //1. Create a function that takes a parameter and returns the parameter's data type
- function dataType(data){
- return typeof data;
- }
- dataType(12);
- dataType('Hello');
- /*2. Create two person objects. Both must have 6 properties: name,
- username, password, age, salary, occupation, and location.
- Create a function that will take an object as an argument and
- returns 'You may enter' if the username is 'tstark' and the password is 'ironman447'.
- */
- person1 = {
- name: 'Bruce Wayne',
- username: 'bwayne',
- password: 'batman123',
- age: 52,
- salary: 20000,
- occupation: 'actor',
- location: 'USA'
- }
- person2 = {
- name: 'Tony Stark',
- username: 'tstark',
- password: 'ironman447',
- age: 47,
- salary: 1000000,
- occupation: 'actor',
- location: 'America'
- }
- function login (obj){
- if (obj.username === 'tstark' && obj.password === 'ironman447')
- return ('You may enter');
- }
- login(person2);
- /*
- 3. Create another function that takes an object as
- an argument and alerts the object's location.
- */
- function alertLocation(obj) {
- alert(obj.location);
- }
- alertLocation(person2);
- /*
- 4. Create another function that takes an object as an argument and
- alerts 'Become a developer' if the age is 18 or older, salary is less
- than $60,000, and occupation is not 'developer'.
- */
- function programmer (obj){
- if (obj.age>=18 && obj.salary <60000 && obj.occupation!='developer') {
- alert('Become a developer!');
- } else {
- alert('Keep it up!');
- }
- }
- programmer(person1); // Become a developer
- programmer(person2); // Keep it up!
Add Comment
Please, Sign In to add comment