Question

only in javascript 1.Define a method named roleOf that takes the name of an actor as...

only in javascript

1.Define a method named roleOf that takes the name of an actor as an argument and returns that actor's role. Ex: roleOf("Keira Knightley") returns "Elizabeth Swann". Hint: A method may access the object's properties using the keyword this. Ex: this.cast accesses the object's cast property.

var movie = { // Code will be tested with different actors and movies
name: "Pirates of the Caribbean: At World's End",
director: "Gore Verbinski",
composer: "Hans Zimmer",
cast: {
"Johnny Depp": "Jack Sparrow",
"Orlando Bloom": "Will Turner",
"Keira Knightley": "Elizabeth Swann",
"Geoffrey Rush": "Hector Barbossa"
},
roleOf: function(actorName) {

/* Your solution goes here */

}
};

--------------------------------------------------------------------------------------

2.

A drink costs 2 dollars. A hamburger costs 5 dollars. Given the number of each, compute total cost and assign to totalCost. Ex: 2 drinks and 3 hamburgers yields totalCost of 19.

var drinkQuantity = 2; // Code tested with values: 2 and 4
var hamburgerQuantity = 3; // Code tested with values: 3 and 7

var totalCost = 0;

----------------------------------------------------------------------------------

3.Loop through the characters in the string wiseProverb and assign numAppearances with the number of times 'e' appears in the string.

var wiseProverb = "When in Rome do as Romans do."; // Code will be tested with "You can lead a horse to water, but you can't make him drink. If you want something done right, you have to do it yourself."
var numAppearances = 0;

/* Your solution goes here */

-------------------------------------------------------------------------------

4.

Update the variable newsUpdated to the month July using Date methods.

var newsUpdated = new Date(2010, 3, 21);

/* Your solution goes here */

--------------------------------------------------------------------

5.

Add a throw statement to the processNumbers function that throws the message "All elements in the list should be numbers." if one of the elements in numberList is not a number. Hint: The function isNaN() returns true if the parameter is not a number.

function processNumbers(numberList) { // Code will be tested with different values of numberList
var result = 0;

for (var index = 0; index < numberList.length; index++) {
  
/* Your solution goes here */
  
result += numberList[index] * 1.3 * index;
}

return result;
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please let me know if you need more information:-

=============================================


<html>
<body>
<p id="demo"></p>
<script>
/*
1.Define a method named roleOf that takes the name of an actor as an argument and returns that actor's role. Ex: roleOf("Keira Knightley") returns "Elizabeth Swann". Hint: A method may access the object's properties using the keyword this. Ex: this.cast accesses the object's cast property.
*/
var movie = { // Code will be tested with different actors and movies
name: "Pirates of the Caribbean: At World's End",
director: "Gore Verbinski",
composer: "Hans Zimmer",
cast: {
"Johnny Depp": "Jack Sparrow",
"Orlando Bloom": "Will Turner",
"Keira Knightley": "Elizabeth Swann",
"Geoffrey Rush": "Hector Barbossa"
},
roleOf: function(actorName) {
/* Your solution goes here */
return this.cast[actorName];
}
};
document.getElementById("demo").innerHTML = movie.roleOf("Keira Knightley");
document.getElementById("demo").innerHTML += "<hr>";

/*
A drink costs 2 dollars. A hamburger costs 5 dollars. Given the number of each, compute total cost and assign to totalCost. Ex: 2 drinks and 3 hamburgers yields totalCost of 19.
*/
var drinkCost = 2;
var hamburgerCost = 5;

var drinkQuantity = 2; // Code tested with values: 2 and 4
var hamburgerQuantity = 3; // Code tested with values: 3 and 7

var totalCost = (drinkCost * drinkQuantity) + (hamburgerCost* hamburgerQuantity);
document.getElementById("demo").innerHTML += "totalCost:" + totalCost;

drinkQuantity = 4;
hamburgerQuantity = 7;

totalCost = (drinkCost * drinkQuantity) + (hamburgerCost* hamburgerQuantity);
document.getElementById("demo").innerHTML += "<br> totalCost:" + totalCost;
document.getElementById("demo").innerHTML += "<hr>";


/*
3.Loop through the characters in the string wiseProverb and assign numAppearances with the number of times 'e' appears in the string.

var wiseProverb = "When in Rome do as Romans do."; // Code will be tested with "You can lead a horse to water, but you can't make him drink. If you want something done right, you have to do it yourself."
*/

var numAppearances = 0;
/* Your solution goes here */
var wiseProverb = "When in Rome do as Romans do.";
for(var i=0; i <wiseProverb.length;i++){
   if(wiseProverb[i] == 'e'){
   numAppearances++;
}
}
document.getElementById("demo").innerHTML += "The number of times 'e' appears in the string:" + numAppearances;

numAppearances=0;
wiseProverb = "You can lead a horse to water, but you can't make him drink. If you want something done right, you have to do it yourself.";
for(var i=0; i <wiseProverb.length;i++){
   if(wiseProverb[i] == 'e'){
   numAppearances++;
}
}
document.getElementById("demo").innerHTML += "<br> The number of times 'e' appears in the string:" + numAppearances;
document.getElementById("demo").innerHTML += "<hr>";

/* 4.Update the variable newsUpdated to the month July using Date methods.
var newsUpdated = new Date(2010, 3, 21); */
/* Your solution goes here */
var newsUpdated = new Date(2010, 3, 21);
newsUpdated.setMonth(6); //6 represents july month
document.getElementById("demo").innerHTML += newsUpdated;
document.getElementById("demo").innerHTML += "<hr>";

/*
5.Add a throw statement to the processNumbers function that throws the message "All elements in the list should be numbers." if one of the elements in numberList is not a number. Hint: The function isNaN() returns true if the parameter is not a number.
*/
function processNumbers(numberList) { // Code will be tested with different values of numberList
var result = 0;

for (var index = 0; index < numberList.length; index++) {
  
/* Your solution goes here */
if(isNaN(numberList[index])) {
throw "All elements in the list should be numbers."
}
  
result += numberList[index] * 1.3 * index;
}

return result;
}

try{
result = processNumbers(['2','5','6',"w",'56']);
document.getElementById("demo").innerHTML += result;
}catch(err){
document.getElementById("demo").innerHTML += err;
}
document.getElementById("demo").innerHTML += "<hr>";

</script>

</body>
</html>

===

OUTPUT;-

==

Elizabeth Swann

totalCost:19
totalCost:43

The number of times 'e' appears in the string:2
The number of times 'e' appears in the string:8

Wed Jul 21 2010 00:00:00 GMT+0530 (India Standard Time)

All elements in the list should be numbers.

==

==

==

==

==

==

Please let me know if you need more information.

==

Thanks

Add a comment
Know the answer?
Add Answer to:
only in javascript 1.Define a method named roleOf that takes the name of an actor as...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Question: A drink costs 5 dollars. A taco costs 7 dollars. Given the number of each,...

    Question: A drink costs 5 dollars. A taco costs 7 dollars. Given the number of each, compute total cost and assign to totalCost. Ex: 2 drinks and 3 tacos yields totalCost of 31. On my screen, there is a box below this question and it has: var drinkQuantity = 2; // Code tested with values: 2 and 4 var tacoQuantity = 3; // Code tested with values: 3 and 7 SPACE var totalCost = 0; I am supposed to put...

  • Write a statement that creates a RegExp object that remembers the first and last name, but...

    Write a statement that creates a RegExp object that remembers the first and last name, but does not remember the title. Using the RegExp object's exec() method, assign the result variable with the remembered first and last name of the string userName. var userName = "Dr. Greg House"; // Code will also be tested with "Mr. Howard Wolowitz" /* Your solution goes here */ console.log(result[1] + " " + result[2]);

  • 1. Assign numMatches with the number of elements in userValues that equal matchValue. userValues has NUM_VALS...

    1. Assign numMatches with the number of elements in userValues that equal matchValue. userValues has NUM_VALS elements. Ex: If userValues is {2, 1, 2, 2} and matchValue is 2 , then numMatches should be 3. Your code will be tested with the following values: matchValue: 2, userValues: {2, 1, 2, 2} (as in the example program above) matchValue: 0, userValues: {0, 0, 0, 0} matchValue: 10, userValues: {20, 50, 70, 100} What i am given: import java.util.Scanner; public class FindMatchValue...

  • Assign numMatches with the number of elements in userValues that equal matchValue. userValues has NUM_VALS elements....

    Assign numMatches with the number of elements in userValues that equal matchValue. userValues has NUM_VALS elements. Ex: If userValues is {2, 2, 1, 2} and matchValue is 2 , then numMatches should be 3. Your code will be tested with the following values: * matchValue: 2, userValues: {2, 2, 1, 2} (as in the example program above) * matchValue: 0, userValues: {0, 0, 0, 0} * matchValue: 50, userValues: {10, 20, 30, 40} (Notes) #include <iostream> #include <vector> using namespace...

  • Before you start For this homework, we will need to import some libraries. You need to...

    Before you start For this homework, we will need to import some libraries. You need to execute the following cell only once; you don't need to copy this in every cell you run. In [ ]: import pandas import numpy from urllib.request import urlretrieve from matplotlib import pyplot %matplotlib inline ​ #This library is needed for testing from IPython.display import set_matplotlib_close set_matplotlib_close(False) Introduction In this homework, you will work with data from the World Bank. The subject of study is...

  • Add JavaScript code in the “find_primeV2.js” to allow users to enter a number, and then based...

    Add JavaScript code in the “find_primeV2.js” to allow users to enter a number, and then based on the number of user enters, to find out how many prime numbers there are up to and including the user inputted number and then display them on the web page. The following are the detailed steps to complete this assignment: Step 1. [30 points] In “find_primeV2.js”, complete isPrime() function by (1) Adding one parameter in function header. That parameter is used to accept...

  • Write a program in C++ that simulates a soft drink machine. The program will need several...

    Write a program in C++ that simulates a soft drink machine. The program will need several classes: DrinkItem, DrinkMachine and Receipt. For each of the classes you must create the constructors and member functions required below. You can, optionally, add additional private member functions that can be used for doing implementation work within the class. DrinkItem class The DrinkItem class will contains the following private data members: name: Drink name (type of drink – read in from a file). Type...

  • Your task is to develop a large hexadecimal integer calculator that works with hexadecimal integers of...

    Your task is to develop a large hexadecimal integer calculator that works with hexadecimal integers of up to 100 digits (plus a sign). The calculator has a simple user interface, and 10 \variables" (n0, n1, ..., n9) into which hexadecimal integers can be stored. For example a session with your calculator might look like: mac: ./assmt1 > n0=0x2147483647 > n0+0x3 > n0? 0x214748364A > n1=0x1000000000000000000 > n1+n0 > n1? 0x100000000214748364A > n0? 0x214748364A > exit mac: Note: \mac: " is...

  • #include <stdio.h> // Define other functions here to process the filled array: average, max, min, sort,...

    #include <stdio.h> // Define other functions here to process the filled array: average, max, min, sort, search // Define computeAvg here // Define findMax here // Define findMin here // Define selectionSort here ( copy from zyBooks 11.6.1 ) // Define binarySearch here int main(void) { // Declare variables FILE* inFile = NULL; // File pointer int singleNum; // Data value read from file int valuesRead; // Number of data values read in by fscanf int counter=0; // Counter of...

  • write in java 1. Assume the availability of a method  named  makeLine that can be passed a non-negative...

    write in java 1. Assume the availability of a method  named  makeLine that can be passed a non-negative integer  n and a character  c and return a String consisting of n identical characters that are all equal to c. Write a method  named  printTriangle that receives two integer  parameters  n and k. If n is negative the method does nothing. If n happens to be an even number, itsvalue is raised to the next odd number (e.g. 4-->5). Then, when k has the value zero, the method prints...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT