Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Javascript Understanding Each question deals with your understanding of javascri

ID: 3717407 • Letter: J

Question

Javascript Understanding

Each question deals with your understanding of javascript

This section is you explaining code. Write your explanation and submit it from the answer textbox.

Try to be as technical as you can with your explanation, but the important part here is to demonstrate your understanding of javascript.

Question 1

What is newArr?

explain why newArr contains those values

            var arr = [2, 4, 6, 8];

            var newArr = [];

            var a = 0;

            var b = 0;

            for (var i = 0; i < 4; i++) {

                a = arr[i];

                b = arr.length - i;

                newArr.push(a + b);

            }

               

Question 2

Upon invoking/calling the Bill function, what parameter value do we need to pass to this function, in order to console.log("Got Ya!)"

Explain what happen to the values for it to get to the console.log

                var bill = function(amount){

                    if(amount > 10 && amount <100){

                      

                       return amount + tax(amount, 1);

                    }

                    else if(amount >= 100){

                        return amount + tax(amount, 2);

                    }

                    else {

                        return amount;

                    }

               

                }

               

               

                var tax = function(price, bracket){

                        if(bracket === 1){

                        return price * 0.1;

                    }

                    else if(bracket === 2){

                     

                      console.log("Got ya!")

                     

                      return price * .2;

                    }

                    else {

                        return 0;

                    }

               

                }

   

Question 3

what's the difference between the two sets of curly braces?

            function doSomething() {

                var a = 5;

               var b = 10;

              }

             

              var something = {

                a: 5,

                b: 10

              }

               

Question 4

What is the name and salary when the script runs giveRaise(p)?

Explain what happen to the values for the name and salary you chose?

            function getP() {

                var person = {};

                person.fName = 'Hector';

                person.lName = 'Arias';

                person.salary = 50000;

   

                return person;

   

                getP2(person);

            }

   

            function getP2(name) {

   

                giveRaise(name);

   

            }

   

           

            function giveRaise(emp) {

                emp.fName;

                emp.salary * 2;

   

            }

   

            var p = getP();

   

            giveRaise(p);

   

Explanation / Answer


1)
var arr = [2, 4, 6, 8];

            var newArr = [];

            var a = 0;

            var b = 0;

            for (var i = 0; i < 4; i++) {

                a = arr[i];

                b = arr.length - i;

                newArr.push(a + b);

            }

First Iteration : a = 2 and b = 4 , So added newArr = [6]
Second Iteration : a = 4 and b = 3 , So added newArr = [6, 7]
Third Iteration : a = 6 and b = 2 , So added newArr = [6, 7, 8]
Fourth Iteration : a = 8 and b = 1 , So added newArr = [6, 7, 8, 9]



2) We need to pass
function(2, 2) => bracket should be 2


3) The difference is doSomething()is a function that will initialise the value a and b
where as something is an object which initialise a and b to the value


4)  Name :  Hector
Salary will be : 50000 * 2 = 100000

Thanks

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote