• Search form is empty!

  • 011 TypeScript - switch statements

    http://robertdunaway.github.io

    TypeScript code kata list

    All code kata lists

    Smiley face

    011 TypeScript - switch statements

    Duration

    10 minutes

    Brief

    Using switch statements

    For more information

    BING/GOOGLE: “TypeScript switch”

    Instructions

    Get tutorial folder or the entire katas-typescript repo.
    Open the [before/*.sln] file and execute the kata.
    Feel free to execute this kata multiple times because repetition creates motor memory.

    Github

    Kata

    Create a variable and then compare it in a switch statement then output the results to the console.


    
        var result: string = 'dog';
    
        switch (result) {
            case 'cat':
                {
                    console.log('a cat was chosen');
                }
            case 'dog':
                {
                    console.log('a dog was chosen');
                }
        }
        Create another switch statement but add a “default”.
    
        switch (result) {
            case 'cat': {
                console.log('a cat was chosen');
            }
            case 'bird': {
                console.log('a bird was chosen');
            }
            default: {
                console.log('the default was used.');
            }
        }
    
    


    Smiley face

    Next

    Take a few minutes and imagine more examples.

    Smiley face

    0 comments:

    Post a Comment