JavaScript JavaScript Loops, Arrays and Objects Tracking Data Using Objects The Student Record Search Challenge Solution

Hui Zheng
PRO
Hui Zheng
Pro Student 1,380 Points

My prompt dialogue didn't pop up

https://w.trhou.se/22d2s0v0wn

I did everything else exactly same as what was shown in the video except I got rid of the other js file and combined the code in the file to the current js file that was created. Besides that I had also checked the html file and removed the extra script tag for the other js file. In terms of the code, I had double checked to make sure I hadn't omitted any curly braces or had any typos, nonetheless the prompt dialogue didn't pop up when I opened up the browser.

1 Answer

KRIS NIKOLAISEN
PRO
KRIS NIKOLAISEN
Pro Student 47,493 Points

Your student_report.js file is in a folder named js. So it will have to be referenced in index.html as

<script src="js\student_report.js"></script>
Hui Zheng
Hui Zheng
Pro Student 1,380 Points

Hi, professor. I have another question regarding the parameter student that was passed onto one of the functions. Initially, the variable student was declared without a value, then inside the for loop we assigned it the object literal students[i]. I know any variables declared inside a function have local scope and can't be accessed outside that function, but what about inside a for loop since student = students[i];. Also I was practicing with functions lately and here is the code I wrote which I didn't know what were the mistakes I made, and I would like to know if I could concatenate/adding the call property of a function calculatePrice() to other variables as I did here. Thanks

const taxRate = 0.08; const gamePrice = 50.99; const PS4 = 299.99;

var bankBalance = 400.88; var remainingAmount = parseInt(prompt("What is the spending amount?"));

function calculatePrice(remainingAmount){ remainingAmount = remainingAmount + remainingAmount * taxRate; return remainingAmount.toFixed(2); }

var totalAmount = calculatePrice() + gamePrice + PS4; while (totalAmount < bankBalance) { alert("The amount is within budget." + "<br>" + "$" + totalAmount); if (totalAmount > bankBalance){ alert("Not enough money.") } }