From: j8takagi Date: Sun, 28 Oct 2012 14:04:12 +0000 (+0900) Subject: Spider Monkey版を追加 X-Git-Url: https://j8takagi.net/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=91e79e40a8a3643bad811f71276d0ee90048c273;p=fizzbuzz.git Spider Monkey版を追加 --- diff --git a/javascript/fizzbuzz2.js b/javascript/fizzbuzz2.js new file mode 100644 index 0000000..257635e --- /dev/null +++ b/javascript/fizzbuzz2.js @@ -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; +}