Spider Monkey版を追加
authorj8takagi <info@j8takagi.net>
Sun, 28 Oct 2012 14:04:12 +0000 (23:04 +0900)
committerj8takagi <info@j8takagi.net>
Sun, 28 Oct 2012 14:04:12 +0000 (23:04 +0900)
javascript/fizzbuzz2.js [new file with mode: 0644]

diff --git a/javascript/fizzbuzz2.js b/javascript/fizzbuzz2.js
new file mode 100644 (file)
index 0000000..257635e
--- /dev/null
@@ -0,0 +1,22 @@
+#!/usr/local/bin/js
+min = 1;
+max = 100;
+
+for(i = min; i <= max; i++) {
+    print(fizzbuzz(i));
+}
+
+function fizzbuzz(n) {
+    fizz = (n % 3 == 0);
+    buzz = (n % 5 == 0);
+    if(fizz && buzz) {
+        fb = "FizzBuzz";
+    } else if(fizz) {
+        fb = "Fizz";
+    } else if(buzz) {
+        fb = "Buzz";
+    } else {
+        fb = n;
+    }
+    return fb;
+}