JavaScript Review

Question 1

There are two functions being called in the code sample below. Which one returns a value? How can you tell?

let grade = calculateLetterGrade(96);
submitFinalGrade(grade);
calculateLetterGrade does beacuse it returns the value to the variable grade
Question 2

Explain the difference between a local variable and a global variable.

global are ble to be used anywhere while local are whithin there container.
Question 3

Which variables in the code sample below are local, and which ones are global?

var stateTaxRate = 0.06;
var federalTaxRate = 0.11;

function calculateTaxes(wages){
	var totalStateTaxes = wages * stateTaxRate;
	var totalFederalTaxes = wages * federalTaxRate;
	var totalTaxes = totalStateTaxes + totalFederalTaxes;
	return totalTaxes;
}
global: stateTaxRate, federalTaxRate, wages
local: totalStateTaxes, totalFederalTaxes, totalTaxes
Question 4

What is the problem with this code (hint: this program will crash, explain why):

function addTwoNumbers(num1, num2){
	var sum = num1 + num2;
	alert(sum);
}

alert("The sum is " + sum); // this has to go! 
addTwoNumbers(3,7);
you need to get rid of the alert befor the function call, or you coud replace the alert in the function.
Question 5

True or false - All user input defaults to being a string, even if the user enters a number.

TRUE
Question 6

What function would you use to convert a string to an integer number?

parseInt()
Question 7

What function would you use to convert a string to a number that has a decimal in it (a 'float')?

parseFloat()
Question 8

What is the problem with this code sample:

var firstName = prompt("Enter your first name");
if(firstName = "Bob"){
	alert("Hello Bob! That's a common first name!");
}
the fact the variable was diclared with var, joking. you used the declertion opperater insted of the equality opperater in the if statment.
Question 9

What will the value of x be after the following code executes (in other words, what will appear in the log when the last line executes)?

var x = 7;
x--;
x += 3;
x++;
x *= 2;
console.log(x);
7-1=6+3+1=10*2=20, it would be 20
Question 10

Explain the difference between stepping over and stepping into a line of code when using the debugger.

step over will go through like normal one line after another but it wont go over the steps of functions. step in walkes you trough the function steps.

Coding Problems

Coding Problems - See the 'script' tag at the bottom of the page. You will have to write some JavaScript code in it.