Data Types and Variables Lab

Lab

Lab time is designed for you to prepare for upcoming lessons, and practice what you have learned so far. Both aspects are important for your success. During this time, you are encouraged to collaborate with fellow students, and reach out to instructors with any and all questions!

Practice

Fork this repl and complete the exercises in the datatypes.cs file.

To complete the exercises, you will first remove the lines that say /* REMOVE THIS LINE and AND REMOVE THIS LINE */. After removing these lines, you will either complete some code by replacing the blank lines (__), or insert code where indicated (Your Code Here). Once you have completed an exercise, run the program, and you will see a confirmation output to the console if the exercise is correct.

See the images below for clarification, and ask an instructor if you have any confusion!

An unstarted exercise looks like this:

Before starting the exercise, remove the indicated lines:

In this example, you would replace // Your code here with the code that creates a string variable called words. Then, when you run the program, you should see:

Complete each of the exercises in this file - you are encouraged to work with others in your cohort!

Keep an eye on Slack. Your instructor will call the group together to review the String Method and Property exercises

Preparation

Math Operations

It is often necessary to do simple math equations. Watch the video below to get an introduction to Math in C#:

Image of Video 'How to do Math'

When performing math, and other sequential operations, it is important to understand any default order by which our programs might perform operations. Watch this video to learn more:

Image of Video 'Order of Operations'

After watching these videos, in the repl that you forked during the Practice segment, work through the exercises in the math.cs file. These exercises are formatted similarly to the practice exercises, and you are encouraged to continue to work with each other and ask questions as you go!

String Interpolation and Concatenation

It is common in programming to interpolate (or, bring together) multiple pieces of data into one string. Work through Sections 1 and 2 of this tutorial to get an introduction.

We have already seen another common string manipulation strategy: concatenation. Concatenation appends or prepends additional information onto an existing string; in other words, it adds something to the end or beginning of an existing string. Read through the Microsoft Concatenate Documentation. There is a lot of information here (as with most documentation!); not all of it is absolutely necessary to know. The most important things will be the information that helps you answer the questions below.

After working through the tutorial, answer the following questions in a notebook:

  1. Are there any differences between the following code statements? If yes, how are they different? A good sentence starter might be: When I run this code, this is what happens…
    • var age = "3" + "2";
    • var age = 3 + 2;
  2. Brainstorm one or more reasons why we might use string interpolation.
  3. In your own words, define ‘interpolation’.

User Input

In our Intro to Programming lesson, we learned that one of the key components of a computer is input. We will be leveraging input from users from here on. To explore this idea:

  1. Work through this tutorial
  2. Read through this resource
    • note that on the W3 site, you can ‘Try It Yourself’ to play around with the examples!

Put what you have just learned into practice, by completing the exercise in the userInput.cs file for the repl that you forked earlier. Remember to reach out to instructors and other students if you have any questions or want to collaborate!

Keep an eye on Slack. Your instructor will call the group together to review the User Input exercise

Lesson Search Results

Showing top 10 results