oyelowoTobiJS.zip

<script> //Task 1 function isOldEnoughToDrink(age){ var validAge = 18; if(age >= validAge){ console.log(true); } else{ console.log(false); } } isOldEnoughToDrink(22); isOldEnoughToDrink(18); isOldEnoughToDrink(5); //Task 2 function isOldEnoughToDrinkAndDrive(age){ var drinkingAge = 21; var canDrinkAndDrive = false; if( age>= drinkingAge && canDrinkAndDrive == false){ console.log(false); } else{ console.log(false) } } isOldEnoughToDrinkAndDrive(25); isOldEnoughToDrinkAndDrive(21); isOldEnoughToDrinkAndDrive(15); //Task 3 var car = {color:'white', model:'toyota'}; function getProperty(objectName,keyName){ return objectName[keyName]; } var output= getProperty(car,'color'); console.log(output); var output= getProperty(car,'model'); console.log(output); var output= getProperty(car,'weight'); console.log(output); //Task 4 var person = {}; function addProperty(myObj,myProperty){ myObj[myProperty] = true; console.log(myObj[myProperty]); } addProperty(person,'male'); //Task 5 var person = {age:21}; function isPersonOldEnoughToDrinkAndDrive(object){ var drinkingAge = 18; var drivingAge = 18; var canDrinkAndDrive = false; if( object['age'] >= drinkingAge && object['age'] >= drivingAge && canDrinkAndDrive == false){ return false; } else{ return false; } } var output = isPersonOldEnoughToDrinkAndDrive(person); console.log(output); //Task 6 function computeAverageLengthOfWords(word1,word2){ return (word1.length + word2.length)/2; } var output = computeAverageLengthOfWords('code', 'programs'); console.log(output); </script>
Javascript Stutern Task

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.