Coder Social home page Coder Social logo

golang-exercises's Introduction

HandsOn Ninja Exercise 01 - 01

1. Using the short declaration operator, ASSIGN these VALUES to VARIABLES with the
    IDENTIFIERS “x” and “y” and “z”
    a. 42
    b. “James Bond”
    c. true
2. Now print the values stored in those variables using
    a. a single print statement
    b. multiple print statements

HandsOn Ninja Exercise 01 - 02

1. Use var to DECLARE three VARIABLES. The variables should have package level
scope. Do not assign VALUES to the variables. Use the following IDENTIFIERS for the variables and make sure the variables are of the following TYPE (meaning they can store VALUES of that TYPE).
    a. identifier “x” type int
    b. identifier “y” type string
    c. identifier “z” type bool
2. in func main
    a. print out the values for each identifier
    b. The compiler assigned values to the variables. What are these values called?

HandsOn Ninja Exercise 01 - 03

Using the code from the previous exercise,
1. At the package level scope, assign the following values to the three variables
   a. for x assign 42
   b. for y assign “James Bond”
   c. for z assign true
2. in func main
  a. use fmt.Sprintf to print all of the VALUES to one single string. ASSIGN the returned value of TYPE string using the short declaration operator to a VARIABLE with the IDENTIFIER “s”
  b. print out the value stored by variable “s”

HandsOn Ninja Exercise 01 - 04

● FYI - nice documentation and new terminology “underlying type”
○ https://golang.org/ref/spec#Types For this exercise
1. Create your own type. Have the underlying type be an int.
2. create a VARIABLE of your new TYPE with the IDENTIFIER “x” using the “VAR”
  keyword
3. in func main
    a. print out the value of the variable “x”
    b. print out the type of the variable “x”
    c. assign 42 to the VARIABLE “x” using the “=” OPERATOR
    d. print out the value of the variable “x”

HandsOn Ninja Exercise 01 - 05

Building on the code from the previous example
1. At the package level scope, using the “var” keyword, create a VARIABLE with the IDENTIFIER “y”. The variable should be of the UNDERLYING TYPE of your custom TYPE “x”
a. eg:
    type UserId int
    var x UserId
    var y int
2. in func main
    a. this should already be done
        i. print out the value of the variable “x”
        ii. print out the type of the variable “x”
        iii. assign your own VALUE to the VARIABLE “x” using the “=” OPERATOR
        iv. print out the value of the variable “x”
b. now do this
    i. now use CONVERSION to convert the TYPE of the VALUE stored in “x” to the UNDERLYING TYPE
        1. then use the “=” operator to ASSIGN that value to “y”
        2. print out the value stored in “y”
        3. print out the type of “y”

HandsOn Ninja Exercise 02 - 01

Using the following operators, write expressions and assign their values to variables:
    g. ==
    h. <=
    i. >=
    j. !=
    k. <
    l. >
Now print each of the variables.

golang-exercises's People

Contributors

ykamran avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.