From b8715367c02bc2c2bbe0b7b4297d7c7fc3d21372 Mon Sep 17 00:00:00 2001 From: jsaasta Date: Tue, 17 Sep 2024 11:18:51 +0200 Subject: [PATCH] Created Examples (markdown) --- Examples.md | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 Examples.md diff --git a/Examples.md b/Examples.md new file mode 100644 index 0000000..404d447 --- /dev/null +++ b/Examples.md @@ -0,0 +1,87 @@ +# Examples + +## if-statement + + if(a < 0){ + // ... + } else if(a > 0) { + // ... + } else { + // ... + } + +## for-loop + + for(var i = 0; i < 10; i = i + 1){ + print i; + } + +## while-loop + + var a = 0; + while(a < 10){ + a = a + 1; + } + +## Functions & Callbacks + + function add(a, b) { + return a + b; + } + + function foo(bar){ + var a = 1; + var b = 2; + return bar(a, b); + } + + print add(4,5); // prints 9 + print foo(add); // prints 3 + + + + +# Classes and inheritance + + class FooParent { + + welcome(){ + print "Hello from Parent"; + } + } + + class Foo < FooParent { + + init(helloString){ + this.helloString = helloString; + } + + welcome(){ + super.welcome(); + print this.helloString; + } + } + + var hello = "Hello World!"; + var foo = Foo(hello); + foo.welcome(); + +--- + + class Person { + + init(name){ + this.name = name; + } + + whoAmI() { + return "This persons name is: " + this.name; + } + + } + var john = Person("John"); + john.age = 30; //Initialize new variables outside of class + + print john.whoAmI(); + + print john.age;