Question

In: Computer Science

Write a JavaScript script that has subprograms nested three deep and in which each nested subprogram...

Write a JavaScript script that has subprograms nested three deep and in which each nested subprogram references variables defined in all of its enclosing subprograms

Solutions

Expert Solution

Here is the program that can help you:

<script>
function ParentFunction() {
    var parentX = 5;
    console.log(parentX);
    function subChild1() {
        var subChild1Y = parentX + 15;
        console.log(subChild1Y);
        function subChild2() {
            var subChild2Z = (subChild1Y + parentX) * 2;                    
            console.log(subChild2Z);
            function finalSubChild() {
                var final = parentX + subChild1Y + subChild2Z; 
                console.log(final);
                alert('Alert From Deepest Nested Function\nParentX = '+ parentX +'\nsubChildY = '+ subChild1Y +'\nsubChildZ = '+ subChild2Z +'\nadded together = '+final);
    }
    finalSubChild();
    }
    subChild2();
    }
    subChild1();
    }ParentFunction();

</script>

Few screenshots that can help you even better:

I hope this will help you. Do upvote if it helps you. Thanks.


Related Solutions

Write a python program that has subprograms (functions) nested 3 deep. Each subprogram should reference variables...
Write a python program that has subprograms (functions) nested 3 deep. Each subprogram should reference variables defined in each of its enclosing subprograms. To submit this program, copy/paste the program and a screenshot of your output when you run it. Use comments liberally so that we can understand your work! You can run JavaScript wherever you prefer, but it is available on repl.it.
Write a simple PHP script. In your script use all of the following: HTML, Javascript, and...
Write a simple PHP script. In your script use all of the following: HTML, Javascript, and PHP.
5) Write a JavaScript script that will ask the user to enter in the length of...
5) Write a JavaScript script that will ask the user to enter in the length of the side of a cube. (all the sides of a cube are equal) Based on the value that is entered by the user from the keyboard, calculate each of the following and assign your results to variables. 1. volume of the cube 2. surface area of the cube 3. volume of the largest sphere that could fit in the box. 4. surface area of...
Nested Loops Problem 3 Write a function called makesentence() that has three parameters: nouns, verbs, and...
Nested Loops Problem 3 Write a function called makesentence() that has three parameters: nouns, verbs, and gerunds. Each parameter is a list of strings, where nouns list has noun strings (such as 'homework'), verbs list has veb strings (such as 'enjoy'), and gerunds list has gerund strings (those -ing words, such as 'studying'). The function will go through all these lists in a systematic fashion to create a list of all possible sentences that use all the noun, verb, and...
Write a java program: Write a nested loop program creating an array list of three positions.  The...
Write a java program: Write a nested loop program creating an array list of three positions.  The first loop terminates with a sentinel value of which user is prompted for input to continue of quit.   Inside loop to enter in each position a prompted input of person's first name.  After the inside loop, edit the second array location making its value "Boston". Print the array's contents.
Write JavaScript statements to accomplish each of the following tasks: a) Display the value of the...
Write JavaScript statements to accomplish each of the following tasks: a) Display the value of the seventh element of array f. b) Initialize each of the five elements of one-dimensional array g to 8. c) Total the elements of array c, which contains 100 numeric elements. d) Copy 11-element array a into the first portion of array b, which contains 34 elements. e) Determine and print the smallest and largest values contained in 99-element floating- point array w. PLEASE WRITE...
Using MATLAB or Octave, Write a script that prompts the user for the coordinates of three...
Using MATLAB or Octave, Write a script that prompts the user for the coordinates of three points A, B, and C, namely (xA, yA), (xB, yB), (xC, yC), forming a triangle, storing each in a variable (for a total of 6 variables). The script should then calculate the centroid G = (xG, yG) using xG = xA+xB+xC 3 and yG = yA+yB+yC 3 , storing each in a variable. Finally, the script should print all four points. Sample output: Enter...
In this assignment, you will write a Python script to increase the population of each city...
In this assignment, you will write a Python script to increase the population of each city in the world_x database by 10% (rounded). First, add a new column to the "world_x" city table using the following MySQL command: ALTER TABLE `world_x`.`city` ADD COLUMN `Population` DOUBLE NULL DEFAULT NULL AFTER `Info`; The existing population data are stored as JSON datatype in the city table in a field named Info. You learned about JSON data types in Module 2. To obtain the...
(Javascript) Write a function that converts the alphabetical characters of first half of each argument to...
(Javascript) Write a function that converts the alphabetical characters of first half of each argument to uppercase and returns the result as one string. Number/s and special chars are ignored. If the length of string is not even, append an extra "-" (hyphen) to end of it to make it even.
Write a PowerShell script which will prompt user to enter the number of the day of...
Write a PowerShell script which will prompt user to enter the number of the day of the week (e.g. 1,2,3,4,5,6,7) and return the day of the week. (e.g. Sunday...etc.) (Hint: Sunday is the 1st day of the week).
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT