Pretty up scripts with print.
This commit is contained in:
parent
fc99b981a1
commit
fc66a7ecef
@ -1,7 +1,9 @@
|
|||||||
let x = [1, 2, 3];
|
let x = [1, 2, 3];
|
||||||
|
|
||||||
print(x[1]); // prints 2
|
print("x[1] should be 2:");
|
||||||
|
print(x[1]);
|
||||||
|
|
||||||
x[1] = 5;
|
x[1] = 5;
|
||||||
|
|
||||||
print(x[1]); // prints 5
|
print("x[1] should be 5:");
|
||||||
|
print(x[1]);
|
||||||
|
@ -1,2 +1,4 @@
|
|||||||
|
print("x should be 78:");
|
||||||
|
|
||||||
let x = 78;
|
let x = 78;
|
||||||
print(x);
|
print(x);
|
||||||
|
@ -3,7 +3,8 @@
|
|||||||
let /* I am a spy in a variable declaration! */ x = 5;
|
let /* I am a spy in a variable declaration! */ x = 5;
|
||||||
|
|
||||||
/* I am a simple
|
/* I am a simple
|
||||||
multi-line comment */
|
multi-line
|
||||||
|
comment */
|
||||||
|
|
||||||
/* look /* at /* that, /* multi-line */ comments */ can be */ nested */
|
/* look /* at /* that, /* multi-line */ comments */ can be */ nested */
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
// This script runs for-loops
|
// This script runs for-loops
|
||||||
|
|
||||||
let arr = [1,2,3,4];
|
let arr = [1, 2, 3, 4];
|
||||||
|
|
||||||
for a in arr {
|
for a in arr {
|
||||||
for b in [10, 20] {
|
for b in [10, 20] {
|
||||||
|
@ -4,4 +4,6 @@ fn bob() {
|
|||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
print(bob()); // should print 3
|
print("bob() should be 3:");
|
||||||
|
|
||||||
|
print(bob());
|
||||||
|
@ -7,6 +7,10 @@ fn addme(a, b) {
|
|||||||
a + b; // notice that the last value is returned even if terminated by a semicolon
|
a + b; // notice that the last value is returned even if terminated by a semicolon
|
||||||
}
|
}
|
||||||
|
|
||||||
print(addme(a, 4)); // should print 46
|
print("addme(a, 4) should be 46:");
|
||||||
|
|
||||||
|
print(addme(a, 4));
|
||||||
|
|
||||||
|
print("a should still be 3:");
|
||||||
|
|
||||||
print(a); // should print 3 - 'a' is never changed
|
print(a); // should print 3 - 'a' is never changed
|
||||||
|
@ -4,4 +4,6 @@ fn f(a, b, c, d, e, f) {
|
|||||||
a - b * c - d * e - f
|
a - b * c - d * e - f
|
||||||
}
|
}
|
||||||
|
|
||||||
print(f(100, 5, 2, 9, 6, 32)); // should print 4
|
print("f() call should be 4:");
|
||||||
|
|
||||||
|
print(f(100, 5, 2, 9, 6, 32));
|
||||||
|
@ -3,12 +3,12 @@ let b = 123;
|
|||||||
let x = 999;
|
let x = 999;
|
||||||
|
|
||||||
if a > b {
|
if a > b {
|
||||||
print("a > b");
|
print("Oops! a > b");
|
||||||
} else if a < b {
|
} else if a < b {
|
||||||
print("a < b");
|
print("a < b, x should be 0");
|
||||||
|
|
||||||
let x = 0; // this 'x' shadows the global 'x'
|
let x = 0; // this 'x' shadows the global 'x'
|
||||||
print(x); // should print 0
|
print(x); // should print 0
|
||||||
} else {
|
} else {
|
||||||
print("a == b");
|
print("Oops! a == b");
|
||||||
}
|
}
|
@ -1 +1,3 @@
|
|||||||
print(34 + 12); // should be 46
|
print("The result should be 46:");
|
||||||
|
|
||||||
|
print(34 + 12);
|
||||||
|
@ -1,2 +1,4 @@
|
|||||||
|
print("The result should be 182:");
|
||||||
|
|
||||||
let x = 12 + 34 * 5;
|
let x = 12 + 34 * 5;
|
||||||
print(x); // should be 182
|
print(x);
|
||||||
|
@ -1,2 +1,4 @@
|
|||||||
|
print("The result should be 230:");
|
||||||
|
|
||||||
let x = (12 + 34) * 5;
|
let x = (12 + 34) * 5;
|
||||||
print(x); // should be 230
|
print(x);
|
||||||
|
Loading…
Reference in New Issue
Block a user