Lesson 33
Running the Score to Letter Grade Mapper Script in the JavaScript Console
Summary
Transcript Summary
In this session, the instructor tests a solution regarding calculating letter grades based on a score. The key points discussed include:
- Initialization of Score: The score is initially set to 85, which is assigned a letter grade 'B'.
- Console Logging: The instructor demonstrates how to display the letter grade using
console.log
combined with string concatenation to print the variable's value. - JavaScript Execution: Steps are taken to copy the code into the browser's JavaScript console for execution.
- Conditional Logic: The instructor explains the logic behind determining the letter grade through conditional statements (
if
andelse if
):- A score of 85 results in 'B'.
- The instructor removes a previously defined variable to avoid redeclaration issues.
- Testing Different Scores: Various scores are tested to confirm that the correct letter grades are returned:
- 70 results in 'C'
- 60 results in 'D'
- 80 results in 'B'
- 100 results in 'A'
- 8 results in 'F'
- Assumptions: It is noted that the code expects scores to always be within the range of 0 to 100, and there are no checks for values outside this range.
The instructor concludes the session by confirming all cases work correctly and invites the audience to the next lesson.
Video Transcript
Now that we have a solution, let's test it out.
So remember I assigned score to 85 in that letter, whatever.
Now at the end here, let's just do a console log just for testing purposes.
To see what letter we got.
You got the letter grade, whatever.
Now how do we print out the value of a variable here?
We can use string concatenation, remember?
You add a plus and then the name of the variable.
This way.
Okay, so you got the letter grade, whatever.
String concatenation.
Anyway, let's copy all this code to the JavaScript console in your browser, okay?
So let's go back here.
We go back to Firefox and I'm going to paste all that code here.
It's going to be a lot.
So here's all the code.
Keeping my score is 85.
Okay, now let's execute this.
What do you expect we get?
Let's walk through it before we execute.
85 is going to go here.
85 greater than or equal to 90.
False.
Go to the next else if check the condition.
It's the score greater than or equal to 80.
That's true.
So this is going to be letter B. Everything else gets skipped.
Then it goes to the console log and it prints out the message.
You got the letter grade B. Actually, I had already defined the letter variable in this
console.
So sorry about that.
Let me just go back and just remove this letter here with the letter because I had already
defined it and that's going to solve my problem.
Okay?
Without that, let's go.
Okay, you got the letter grade B as we expected.
Now let's try something else.
Let's go back to the code and change the score right here to a, let's see, 70.
70 would give us what?
C, right?
Oops.
I redeclared score because I had already declared before in the previous run.
Sorry about that again.
Let's remove the letter and just do like that.
Try again.
You got the letter grade C. Great.
Let's try for the F. What score would you give to get F?
Let's try 8.
You got the letter grade F. Great.
Let's try the, what else?
We didn't try D. Let's try 69.
You got the letter grade D. And finally, let's get the A. Let's do score 100.
And there you go.
You got the letter grade A. Okay?
So if that's it, all the cases working okay.
Once again, we assumed the score always holds a value between 0 and 100.
So we did not account for values greater than 100 and below 0.
So this is it for our exercise and I'll see you on the next lesson.
No comments yet (loading...)
No comments yet (loading...)
Did you like the lesson? 😆👍
Consider a donation to support our work: