Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1114)

Unified Diff: src/tests/site/code/die.dart

Issue 83663005: added front page samples to testing, plus a couple of tweaks to front page and code lab (Closed) Base URL: https://github.com/dart-lang/dartlang.org.git@master
Patch Set: put front page code snippets under testing, minor tweaks, fixed carousel height problem Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/tests/site/code/die.dart
diff --git a/src/tests/site/code/die.dart b/src/tests/site/code/die.dart
new file mode 100644
index 0000000000000000000000000000000000000000..0e71d2b186419375869d1eb92c86aa887191071c
--- /dev/null
+++ b/src/tests/site/code/die.dart
@@ -0,0 +1,23 @@
+import 'dart:math' show Random; // Import a class from a library.
+
+void main() { // This is where the app starts executing.
Kathy Walrath 2013/11/23 00:46:27 Ew. > 80 characters. Oh well.
+ print(new Die(n: 12).roll()); // Print a new object's value. Chain method calls.
+}
+
+class Die { // Define a class.
+ static Random shaker = new Random(); // Define a class variable.
+ int sides, value; // Define instance variables.
+
+ String toString() => '$value'; // Define a method using shorthand syntax.
+
+ Die({int n: 6}) { // Define a constructor.
+ if (4 <= n && n <= 20) {
+ sides = n;
+ } else {
+ throw new ArgumentError(/* */); // Support for errors and exceptions.
+ }
+ }
+ int roll() { // Define an instance method.
+ return value = shaker.nextInt(sides); // Get a random number.
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698