Saturday, June 10, 2017

Hello World in TypeScript

Hi there I would like to share with you a sample program that I wrote using TypeScript a JavaScript Framework in this sample program it will display hello world with my name in the web page. I am still learning TypeScript during the writing of this code.  Thank you.

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.





Sample Program Output


Program Listing

hello.ts

class Hello {
    constructor (public msg: string){
    }
    sayHello() {
        return "<h2>" + this.msg + "</h2>";
    }
};
var hello = new Hello("Hello World, What do you think of TypeScript Mr. Jake R. Pomperada? ");

document.body.innerHTML = hello.sayHello();

hello.js

var Hello = (function () {
    function Hello(msg) {
        this.msg = msg;
    }
    Hello.prototype.sayHello = function () {
        return "<h2>" + this.msg + "</h2>";
    };
    return Hello;
}());
;
var hello = new Hello("Hello World, What do you think of TypeScript Mr. Jake R. Pomperada? ");

document.body.innerHTML = hello.sayHello();

hello.htm

<!DOCTYPE html>
<html>
  <head><title>TypeScript Hello World | Mr. Jake R. Pomperada </title></head>
  <body>
    <script src='hello.js'></script>
  </body>
</html>


No comments:

Post a Comment