Javascript has 3 basic types of data
Let's Practice!!
JavaScript lets you perform basic mathematical operations like addition, subtraction, multiplication, and division. To make these calculations, we use the symbols +, -, *, and /, which are called operators.
Information or data that changes
var name = "Kenneth";
var myFavoritePokemon = "bulbasaur";
myFavoritePokemon = "Charmander";
var myFavoriteNumber = 12;
var wearsGlasses = true;
OK:
var myPokemon, $myPokemon, _charmander, _Charmander;
Not OK:
var 3MasterBalls, iBeatTheGymLeader!
How do we write my favorite pokemon in camel case?
Find how many seconds is in an hour using variables
*Hint*
seconds in a minute is 60 seconds
minutes in an hour is 60 minutes
Now find how many seconds is in 1 hour
var secondsInAMinute = 60;
var minutesInAnHour = 60;
var secondsInAnHour = secondsInAMinute * minutesInAnHour;
secondsInAnHour;
//The answer is 3600
Find your age in 10 years
Find your age in 10 years
var age = 10;
var inTenYears = 10;
var myFutureAge = age + inTenYears;
console.log(myFutureAge)
//Answer is 20
Strings are written within quotes either “ “ double or ‘ ‘ single
var myFavoriteShow = "Pokemon";
var myFavoriteFood = 'chicken';
var first = “ken”
var last = “banico”
var fullName = first + last
//output will be "kenbanico"
"Supercalifragilisticexpialidocious".length;
34
var myName = "Ken";
myName[0];
//"K"
myName[1];
//"e"
myName[2];
//“n"
Get the 2nd character of each word and print out the secret code
Hint
var myName = "ken";
myName[0];
"k"
var codeWord1 = “igloo”;
var codeWord2 = “buddy”;
var codeWord3 = “cat”;
var codeWord4 = “umbrella”;
var codeWord1 = "igloo";
var codeWord2 = "buddy";
var codeWord3 = "cat";
var codeWord4 = "umbrella";
var theSecret = codeWord1[1]+codeWord2[1]+codeWord3[1]+codeWord4[1];
console.log(theSecret);
Example
var myLongString = "Gotta Catch Em All";
myLongString.slice(6,9);
//Type it out and see what the answer is
var myLongString = "Gotta Catch Em All";
myLongString.slice(6,9);
Start
End
G o t t a
0 1 2 3 4 6 7 8 9 10 12 13 15 16 17
C a t c h
E M
A L L
Spaces are counted
and does not include the last number you specify
Not Included
Try it out with your own String
"Hello there my name is Professer Oak!".toUpperCase();
Example
"hElLo ThERE I liKE POKEMoN".toLowerCase();
Example
See if you can figure out how to make
"hElLo ThERE I liKE POKEMoN"
into
"Hello there i like pokemon"
var complicatedString = "hElLo ThERE I liKE POKEMoN";
//this will get the first firstLetter
var firstLetter = complicatedString[0];
//this will make the firstLetter uppercase
firstLetter = firstLetter.toUpperCase();
//this will get the second letter all the way up to the last letter
var restOfTheString = complicatedString.slice(1)
//this will make the rest of the string toLowerCase
restOfTheString = restOfTheString.toLowerCase();
//we combine the two variables to complete the string
console.log(firstLetter+restOfTheString)