Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict' ;
- // 1. Create a function that takes a parameter and returns the parameter's data type
- function dataType(data){
- return typeof data;
- }
- dataType(false);
- dataType(7);
- dataType('this is a string');
- // 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'.
- var personOne = {
- name: 'Ahmed' ,
- username: 'Ahmed177',
- password:'coolguy123',
- age: 18 ,
- salary: 20000,
- occupation: 'dispatcher',
- location: 'Seattle'
- }
- var personTwo = {
- name: 'Tony' ,
- username: 'tstark' ,
- password: 'ironman447' ,
- age: 28 ,
- salary: 300000,
- occupation: 'superhero',
- location: 'Not seattle'
- }
- function login( obj ){
- if ( obj.username === 'tstark' && obj.password === 'ironman447') {
- return 'You may enter';
- } else{
- return 'Access denied';
- }
- }
- login(personOne);
- login(personTwo);
- // 3. Create another function that takes an object as an argument and alerts the object's location.
- function alertLocation( obj ){
- alert('Location: ' + obj.location) ;
- }
- alertLocation(personOne);
- alertLocation(personTwo);
- // 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 becomeDeveloper(obj){
- if (
- obj.age >= 18 ;
- obj.salary < 60000 ;
- obj.occupation != developer ;
- ) {
- alert('Become a developer') ;
- } else{
- alert('Sorry buddy, not for you.');
- }
- }
- becomeDeveloper(personOne);
- becomeDeveloper(personTwo);
Add Comment
Please, Sign In to add comment