Coder Social home page Coder Social logo

exercise12's Introduction

exercise12

This TypeScript code demonstrates the use of an array, a loop, and string interpolation to print personalized messages for each name in the array. Let's break down the code step-by-step:

  1. let names: string[] = ['Muhammad', 'Ali', 'Javaid', 'Ahmed'];

    • This line declares a variable names and assigns an array of strings to it. The array contains four names: 'Muhammad', 'Ali', 'Javaid', and 'Ahmed'. The type annotation : string[] indicates that this variable can only hold an array of strings.
  2. for (let name of names) { ... }

    • This is a for...of loop. It iterates over each element (in this case, names) of the array names.
  3. console.log(Good morning ${name}, I hope you are having a fantastic day!)

    • Inside the loop, this line uses string interpolation (backticks ``) to create a personalized message for each name in the array. The ${name} part of the string is a placeholder that will be replaced by the current element (name) of the array during each iteration.
  4. During the loop execution:

    • In the first iteration, name will be 'Muhammad', so the message will be: "Good morning Muhammad, I hope you are having a fantastic day!"
    • In the second iteration, name will be 'Ali', so the message will be: "Good morning Ali, I hope you are having a fantastic day!"
    • In the third iteration, name will be 'Javaid', so the message will be: "Good morning Javaid, I hope you are having a fantastic day!"
    • In the fourth iteration, name will be 'Ahmed', so the message will be: "Good morning Ahmed, I hope you are having a fantastic day!"

Overall, this code prints a personalized "Good morning" message for each friend's name present in the names array.

exercise12's People

Contributors

typescriptkamran avatar 6333kamran avatar

Stargazers

Faraz Baber 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.