课程: JavaScript: Scope

今天就学习课程吧!

今天就开通帐号,24,700 门业界名师课程任您挑!

Solution: Define local variable

Solution: Define local variable - JavaScript教程

课程: JavaScript: Scope

Solution: Define local variable

(musical sting) - [Instructor] Let's go through the solution of the challenge. Keep in mind your code could be anything you wanted as long as you're able to validate the local variables aren't available globally. So let's take a look at mine. So what I did here is first define a global variable called number of platoon to 45, then created a function called platoon, and inside of that function I defined two local variables. So one is the warriors per platoon at 60, and then a total warriors, which is the number of platoon multiplied by warriors per platoon, and then returned our army is total warriors strong. So this should give us the 45 multiplied by 60 here and return it inside of this template strings here, and then we console log. So if we save this and we go to our browser, our army is 2700 strong. Also I've put some notes in here. So if we wanna test that warriors per platoon are indeed local and not…

内容