Skip to content

Instantly share code, notes, and snippets.

@Eunit99
Last active June 30, 2021 04:50
Show Gist options
  • Save Eunit99/a18f42c4fa026b5918bc02d139c13ca6 to your computer and use it in GitHub Desktop.
Save Eunit99/a18f42c4fa026b5918bc02d139c13ca6 to your computer and use it in GitHub Desktop.
All Stutern JavaScript Task
// Task 1
function isOldEnoughToDrink(age) {
var output;
if (age >= 18) {
output = true;
console.log(`isOldEnoughToDrink: ${output}`); // --> true
} else {
output = false;
console.log(`isOldEnoughToDrink: ${output}`); // --> false
}
}
isOldEnoughToDrink(22);
// Task 2
function isOldEnoughToDrinkAndDrive(age) {
const output = false;
if (age === age) {
console.log(`isOldEnoughToDrinkAndDrive: ${output}`); // --> false
}
}
isOldEnoughToDrinkAndDrive(22);
// Task 3
function getProperty() {
var obj = {
0: "One",
1: "Two",
2: "Three"
};
let output = obj[1];
console.log(`getProperty: ${output}`); // --> Two
}
getProperty();
// Task 3
function addProperty() {
var obj = {
0: "One",
1: "Two",
2: "Three"
};
let output = obj[1];
console.log(`addProperty: ${output}`);
}
addProperty(3, "Four");
// Task 5
function isOldEnoughToLegallyDrinkAndDrive() {
var obj = {
age: 45
};
const output = false;
console.log(`isOldEnoughToLegallyDrinkAndDrive: ${output}`); // --> false
}
isOldEnoughToLegallyDrinkAndDrive();
// Task 6
function computeAverageLengthOfWords() {
var wordOne,
wordTwo;
wordOne = "code";
wordTwo = "programs";
const output = (wordOne.length + wordTwo.length) / 2;
console.log(`computeAverageLengthOfWords: ${output}`); // --> 6
}
computeAverageLengthOfWords();
//Task 7
function transformFirstAndLast() {
var input = ["Queen", "Elizabeth", "Of Hearts"];
input.splice(0, 1, "Beyonce");
console.log(`transformFirstAndLast: ${input}`); // --> Queen Beyonce
}
transformFirstAndLast();
// Task 8
function getAllKey() {
var inputs = {
name: "Eunit",
age: "22",
place: "Nigeria",
continent: "Africa",
skinColor: "Black"
}
console.log(`getAllKey: ${Object.keys(inputs)}`); // --> name,age,place,continent,skinColor
}
getAllKey();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment