Introduction To Programming
10-152-310

Learning Plan 2 : Variables and Data Types

Source Code


        

Demo Output


        

Explanation


        
  • Lines 4-5 declare number variables. Note the lack of quotation marks.
  • Line 6 declares a string variable even though the contents look like a number. The double-quotes make it a string.
  • Lines 9 prints the "count" variable to the page. The write function converts the number to a string for display automatically.
  • Lines 13 prints the "price" variable to the page.
  • Lines 17 adds price and count together and prints the results to the page.
  • Lines 21 prints the "priceString" variable to the page. Since it is already a string the write function doesn't need to convert it.
  • Lines 25 "adds" the "priceString" variable to the "count" variable and prints the results to the page. However, the plus sign (+) in this case converts the number to a string and then combines both strings together. This is called concatenation.