Loading
Lesson 33
Courses / JavaScript for Complete Beginners
Running the Score to Letter Grade Mapper Script in the JavaScript Console

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: