Vitaly is the Digital Marketing Manager at CodeMonkey. His master's degree in Computer Science, combined with his experience as a father of two sons, helps him create content focused on coding education.
Understanding Variables in Coding – Explained for Kids
In the realm of programming, variables serve as fundamental building blocks. They are crucial components that store values and allow developers to manipulate data efficiently. Whether you’re a novice coder or an experienced programmer, grasping the concept of variables is essential for mastering any programming language. In this video, we’ll delve into the intricacies of variables, exploring their significance, usage, and practical applications.
Watch this CodeMonkey video to learn all about Variables in Computer Coding:
Read the transcript below:
Hello, welcome to Variable Valley! Let’s learn about variables. Variables store values. The values could be numbers, strings or even objects. Here’s a piece of code where we use a variable with the name n, the assignment operator which is the equal sign and the value is 5.
So 5 is stored in the variable n. Later in the code, we could use that variable n with a command such as the step command step n. Since n is 5 we’re stepping 5. So anywhere in your code where you use a number you can use a variable instead, just make sure you assign the variable of value before you use it.
Let’s look at an example.
Here’s an example where we have three variables in the code.
n has the value of five and it looks like n is controlling how many times the loop goes around
x has the value of 5 and it looks like that’s how much we’re stepping each time
d has the value of 72 and that is the amount of degrees that we’re turning each time. And if we look at the challenge you could see the monkey is stepping and turning in order to go in a circular pattern.
Okay so let’s just go ahead and run this and what’s really cool in CodeMonkey is there’s this table here that will tell you the starting value of all the variables and if they change that change will appear there as well.
Oh it looks like we need to change the value of how far it steps. x should actually be 10 And since we change that to 10 now when we step x it’ll say what’s the value of x is 10, so you see how 10 x is 10 now.
Okay let’s look at one more example.
Now in this example you could see that the monkey is stepping in a spiral sort of pattern and first the monkey is stepping eight, turning and then stepping 12, turning, stepping 16, turning, 20, turning and 24.
How are these numbers changing each time? Yeah it’s changing by 4 each time: 8 plus 4 is 12, 12 plus 4 is 16, and so on. And you see how the code they’re giving us They have d is equal to 8 so that’s the initial distance here. And then we have a loop where we’re stepping a certain amount d And then turning left and we’re doing that over and over again. But we want this d to be four more each time so the way you code that is say d equals d plus four.
This is a really common way of coding a variable changing by a certain amount each time. So the way the code works it will evaluate what’s on the right-hand side. Say what’s the current value of d? Eight. Add four to it and then put it into the new value of d and that happens over and over again.
Also let’s just look at this code one two three four five times. I think we actually need to loop five times instead of three so let’s go ahead and run this and remember to look at the variable table to see how it changes.
See this variable table see how d is changing? Cool. I love having this this table! All right, very good. Now that we’ve reviewed variables it’s your turn to try variables!
Pam Rissmann is a middle school STEM teacher who teaches computer science, robotics, and product design. She has been teaching for 15 years, and in addition to teaching, she coaches her school’s competitive math club and STEM Girls club. Pam is a recipient of the Santa Clara County/Texas Instruments STEM teacher award and California League of Middle School Teacher of the Year for her school. Pam was awarded by Project Lead the Way the Outstanding Gateway Teacher award in 2019.
Stay Up To Date on The Latest NEWS AND LEARN MORE ABOUT CODING FOR KIDS.
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept”, you consent to the use of ALL the cookies. However you may visit Cookie Settings to provide a controlled consent.
This website uses cookies to improve your experience while you navigate through the website. Out of these cookies, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may have an effect on your browsing experience.
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Cookie
Type
Duration
Description
_codemonkey_session_rails_4
1
1 year
_ga
persistent
2 years
This cookie is installed by Google Analytics. The cookie is used to calculate visitor, session, campaign data and keep track of site usage for the site's analytics report. The cookies store information anonymously and assign a randomly generated number to identify unique visitors.
cookielawinfo-checkbox-advertisement
persistent
11 months
The cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Advertisement".
cookielawinfo-checkbox-analytics
persistent
11 months
This cookies is set by GDPR Cookie Consent WordPress Plugin. The cookie is used to remember the user consent for the cookies under the category "Analytics".
cookielawinfo-checkbox-functional
persistent
11 months
cookielawinfo-checkbox-necessary
persistent
11 months
This cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-non-necessary
0
11 months
This cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Non Necessary".
cookielawinfo-checkbox-other
persistent
11 months
cookielawinfo-checkbox-performance
persistent
11 months
This cookie is used to keep track of which cookies the user have approved for this site.
JSESSIONID
1
1 year
Used by sites written in JSP. General purpose platform session cookies that are used to maintain users' state across page requests.
viewed_cookie_policy
persistent
1 hour
The cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
XSRF-TOKEN
persistent
1 year
The cookie is set by Wix website building platform on Wix website. The cookie is used for security purposes.
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
Cookie
Type
Duration
Description
rlas3
persistent
11 months
The cookie is set by rlcdn.com. The cookie is used to serve relevant ads to the visitor as well as limit the time the visitor sees an and also measure the effectiveness of the campaign.
UserMatchHistory
persistent
1 month
Linkedin - Used to track visitors on multiple websites, in order to present relevant advertisement based on the visitor's preferences.
This cookie is set by Google Analytics and is used to distinguish users and sessions. The cookie is created when the JavaScript library executes and there are no existing __utma cookies. The cookie is updated every time data is sent to Google Analytics.
__utmb
persistent
30 minutes
The cookie is set by Google Analytics. The cookie is used to determine new sessions/visits. The cookie is created when the JavaScript library executes and there are no existing __utma cookies. The cookie is updated every time data is sent to Google Analytics.
__utmc
persistent
1 year
The cookie is set by Google Analytics and is deleted when the user closes the browser. The cookie is not used by ga.js. The cookie is used to enable interoperability with urchin.js which is an older version of Google analytics and used in conjunction with the __utmb cookie to determine new sessions/visits.
__utmt
persistent
10 minutes
The cookie is set by Google Analytics and is used to throttle request rate.
__utmz
persistent
6 months
This cookie is set by Google analytics and is used to store the traffic source or campaign through which the visitor reached your site.
_gat
persistent
1 minute
This cookies is installed by Google Universal Analytics to throttle the request rate to limit the colllection of data on high traffic sites.
YSC
1
1 year
This cookies is set by Youtube and is used to track the views of embedded videos.
This cookie is used by Google Analytics to understand user interaction with the website.
_gid
persistent
1 day
This cookie is installed by Google Analytics. The cookie is used to store information of how visitors use a website and helps in creating an analytics report of how the wbsite is doing. The data collected including the number visitors, the source where they have come from, and the pages viisted in an anonymous form.
GPS
persistent
30 minutes
This cookie is set by Youtube and registers a unique ID for tracking users based on their geographical location
MR
persistent
5 months
This cookie is used to measure the use of the website for analytics purposes.
MUIDB
1
1 year
This cookie is used by MicroSoft and collects data about users of visits on multiple website. This data is used to analyze the efficiency of advertisements on websites.
This cookie is set by Facebook to deliver advertisement when they are on Facebook or a digital platform powered by Facebook advertising after visiting this website.
bscookie
1
2 years
This cookie is a browser ID cookie set by Linked share Buttons and ad tags.
fr
1
3 months
The cookie is set by Facebook to show relevant advertisments to the users and measure and improve the advertisements. The cookie also tracks the behavior of the user across the web on sites that have Facebook pixel or Facebook social plugin.
IDE
1
2 years
Used by Google DoubleClick and stores information about how the user uses the website and any other advertisement before visiting the website. This is used to present users with ads that are relevant to them according to the user profile.
MUID
persistent
1 year
Used by Microsoft as a unique identifier. The cookie is set by embedded Microsoft scripts. The purpose of this cookie is to synchronize the ID across many different Microsoft domains to enable user tracking.
pxrc
persistent
2 months
The purpose of the cookie is to identify a visitor to serve relevant advertisement.
rlas3
persistent
11 months
The cookie is set by rlcdn.com. The cookie is used to serve relevant ads to the visitor as well as limit the time the visitor sees an and also measure the effectiveness of the campaign.
skimCSP
persistent
11 months
This cookie is set by SkimResources. The cookie is used to record data on the visitor to optimize the relevance of the advretisements served to the users.
TapAd_DID
persistent
2 months
The cookie is set by tapad.com. The purpose of the cookie is to track users across devices to enable targeted advertising
TapAd_TS
persistent
2 months
The cookie is set by Tapad.com. The purpose of the cookie is to track users across devices to enable targeted advertising.
TDCPM
persistent
1 year
The cookie is set by CloudFare service to store a unique ID to identify a returning users device which then is used for targeted advertising.
TDID
persistent
1 year
The cookie is set by CloudFare service to store a unique ID to identify a returning users device which then is used for targeted advertising.
test_cookie
persistent
15 minutes
This cookie is set by doubleclick.net. The purpose of the cookie is to determine if the users' browser supports cookies.
VISITOR_INFO1_LIVE
1
5 months
This cookie is set by Youtube. Used to track the information of the embedded YouTube videos on a website.