6.5.1: Functions. Assign a variable madLib to a function expression that has fiv
ID: 3911408 • Letter: 6
Question
6.5.1: Functions.
Assign a variable madLib to a function expression that has five parameters in the order: two nouns, an adjective, an adverb and a verb. The function should return a mad lib string value by substituting the parameter values into the following template: The [adjective] [noun1] [adverb] [verb] the [noun2]. For example: madLib("dog", "moon", "lazy", "quietly", "smashed") returns "The lazy dog quietly smashed the moon.".
/* Your solution goes here */
/* Code will be tested once with parameters: "dog", "moon", "lazy", "quietly", "smashed",
and again with parameters: "rat", "city", "bored", "gently", "became" */
console.log(madLib("dog", "moon", "lazy", "quietly", "smashed"));
______________________________________________________________________
6.6.1: Arrays.
Multiply each element in sourceArray with the corresponding value in offsetAmount. Store each value in a new array named destinationArray.
var sourceArray = [ 40, 50, 60, 70 ]; // Tests will use different arrays
var offsetAmount = [ 2, 5, 8, 4 ]; // Tests will use different arrays
var destinationArray = [];
/* Your solution goes here *
______________________________________________________________________
6.8.1: Strings.
Use indexOf(), and substr() or substring(), to display the end of the sentence starting from the word "make".
var oldSaying = "Two wrongs don't make a right."; // Code will be tested with "Did you make that robot?"
/* Your solution goes here */
______________________________________________________________________
6.8.2: Using Date methods.
Display the date when Facebook's website launched in M-DD-YYYY format. Ex: The 31st of January 1970 should be displayed as: "1-31-1970".
var interestingEvents = {
"Long distance telegraph": new Date(1844, 4, 24),
"First telephone call": new Date(1876, 2, 10),
"Microsoft founded": new Date(1975, 3, 4),
"World wide web born": new Date(1989, 2, 1),
"Google founded": new Date(1998, 8, 4),
"Facebook website launch": new Date(2004, 1, 4)
};
var interestingDate = interestingEvents["Facebook website launch"]; // Code also tested using date of First telephone call
/* Your solution goes here */
Explanation / Answer
If you have any doubts, please give me comment...
6.5 .1
var madLib = function(noun1, noun2, adjective, adverb, verb) {
return "The " + adjective + " " + noun1 + " " + adverb + " " + verb + " the " + noun2 + ".";
}
console.log(madLib("dog", "moon", "lazy", "quietly", "smashed"));
6.6 .1
var sourceArray = [40, 50, 60, 70]; // Tests will use different arrays
var offsetAmount = [2, 5, 8, 4]; // Tests will use different arrays
var destinationArray = [];
/* Your solution goes here */
for (var i = 0; i < sourceArray.length; i++) {
destinationArray[i] = sourceArray[i] * offsetAmount[i];
}
6.8 .1
var oldSaying = "Two wrongs don't make a right."; // Code will be tested with "Did you make that robot?"
/* Your solution goes here */
var makeInd = oldSaying.indexOf("make");
console.log(oldSaying.substring(makeInd));
6.8 .2
var interestingEvents = {
"Long distance telegraph": new Date(1844, 4, 24),
"First telephone call": new Date(1876, 2, 10),
"Microsoft founded": new Date(1975, 3, 4),
"World wide web born": new Date(1989, 2, 1),
"Google founded": new Date(1998, 8, 4),
"Facebook website launch": new Date(2004, 1, 4)
};
var interestingDate = interestingEvents["Facebook website launch"]; // Code also tested using date of First telephone call
/* Your solution goes here */
console.log((interestingDate.getMonth()+1) + "-" + interestingDate.getDate() + "-" + interestingDate.getFullYear());
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.