let a = 10 println('Hello') println('a: ' + 10)
let x = 5 let name = "Asha Zandaski" let area = this.getArea() _hiddenSource_ //Try It let name = "Asha Zandaski" println(name); //Run your experiments here
let x, name, area x = 5 name = "Asha Zandaski" area = this.getArea() _hiddenSource_ //Try It let name; name = "Asha Zandaski" println(name); //Run your experiments here
var x, name, area x = 5 name = "Asha Zandaski" area = this.getArea() _hiddenSource_ //Try It var name; name = "Asha Zandaski" println(name); //Run your experiments here
elem1.equals(elem2) //object equality num1 == num2 //prim value equality/equals num1 != num2 //prim value not equal x > y //greater than x >= y //greater than or equal to x < y //less than x <= y //less than or equal to a.equals(b) ? 'Test Passed' : 'Test Failed' //ternary _hiddenSource_ //Try It let elem1, elem2, elem3; elem1 = 10; elem2 = 10; elem3 = 20; println(elem1 + " " + elem2 + " " + elem3); println(elem1.equals(elem2)); println(elem1.equals(elem3)); println(!elem1.equals(elem3)); //Run your experiments here
// In real code, use "equals" and "!equals" like this: let boolean1 = a.equals(b) let boolean2 = !a.equals(b) // Do not either of "==" or "!=" let boolean1 = a == b let boolean2 = a != b /*Exception to this rule -- only if you are certain that both of your operands will be primitives, then you could (optionally) use "==" or "!=" (but "equals" will work also).*/ //if it is known that both operands are primitives, this is okay: let isEqual = index1 == 10 // This is also okay let isEqual = index1.equals(10)
(x > y) && (x > 10) //"&&" is the "and" operator //checks if both left and right are true (x > y) || (x > 10) //"||" is the "or" operator //checks if either left or right are true !(0==1) //"!" is the "not" operator -- inverts (flips) // (example here would be true) _hiddenSource_ //Try It let x, y; x = 20; y = 15; println((x > y) && (x > 10)); //Run your experiments here
x = a + b; //addition x = a - b; //subtraction x = a * b; //multiplication x = a / b; //division x = a % b; //modulus (remainder) x++; //shorthand for "x = x + 1" x--; //shorthand for "x = x - 1" _hiddenSource_ //Try It let x, a, b; a = 20; b = 15; println("a: " + a); println("b: " + b); println("a % b: " + a % b); //Run your experiments here
let array = Array.newFixed(2);
let array = Array.newFixed(2); //At index=0, set value 10 array[0] = 10; //At index=1, set value 20 array[1] = 20; println(array);
let array = Array.newFixed(2); array[0] = 10; array[1] = 20; //Get element at index=0, then element at index=1 println(array[0]); //or println(array.get(0));
let array = Array.newDynamic();
let array = Array.newDynamic();
array.add(40);
array.add(30);
array.add(20);
array.add(10);
println(array);
let a = [2, 4, 6, 8];
println(a);
let a = [2, 4, 6, 8];
println(a.length);
println(a.size());
if (CONDITION) {
}
if (a > b) { println('yep, a is larger') } _hiddenSource_ //Try It let a = 100; let b = 99; if (a > b) { println('yep, a is larger') } //Run your experiments here
if (CONDITION) {
} else {
}
if (a > b) { println('a is larger') } else { println('b is larger') } _hiddenSource_ //Try It let a = 100; let b = 101; if (a > b) { println('a is larger') } else { println('b is larger') } //Run your experiments here
/** Iterates using while loop and index */ function printAll(list) { let len = list.length1let i = 0 while (2i < len) { let eachElem = list[i] println(eachElem)3i++ } } //Try It let myList = ['Asha', 'Chin', 'Kofi']; printAll(myList);
/** Iterates over objects (when index is not needed) */ function printAll(list) {1for (let2eachElem of list) { println(3eachElem) } } //Try It let myList = ['Asha', 'Chin', 'Kofi']; printAll(myList);
/** Iterates using while loop and index (abbreviated syntax) */ function printAll(list) { for (1let nextIndex = 0;2nextIndex < list.length;3nextIndex++) { let nextElem = list[nextIndex] println(nextElem) } } //Try It let myList = ['Asha', 'Chin', 'Kofi']; printAll(myList);
//Outputs the triple of input x let tripleNumFct = (x) => 3 * x //Try It let x = 10; let y = tripleNumFct(x); println(y);
let getFirstFct = (array) => array.get(0); let array = ['A++', 'A', 'A-']; let result = getFirstFct(array); println('Result is ' + result);
let getFirstFct = (array) => array.get(0); let array = ['A++', 'A', 'A-']; let result = getFirstFct(array); println('Result is ' + result);
class Foo { }
initialize() { // Initialize this object this.contents = []; this.position = 0; }
this.println() let width = this.width let area = this.computeArea()
//get property from "this" object (i.e., the current object) width = this.width //get property 'length' from object 'bigList' len = bigList.length
bigList.reverse() this.setWidth(10) this.computeResult()
foo.println() //okay without ';' foo.println(); //okay with ';'
throw "index out of range"