5
0
My teacher gave me a simple problem which I should solve with a code tiny as possible. I should print all odd numbers from 0 to 100000 into a HTML document using javascript.
for(var y = 0; y < 100000; y++){
if(!(y % 2 == 0)){
document.write(y + " ");
}
};
Is it possible to do that shorter?
By shorter do you mean Javascript only or any language? – Sp3000 – 2014-12-25T12:09:35.310
The problem should be solved in JS only. – Max Krause – 2014-12-25T12:10:33.267
17-1 for needlessly restriction on the language – Johannes Kuhn – 2014-12-25T17:52:05.510
7
@JohannesKuhn language-specific questions asking for golfing advice are perfectly on-topic
– Martin Ender – 2014-12-25T18:16:26.3133-1 for asking us to do your homework better. – R-D – 2014-12-27T01:36:58.210
The non-golfed Perl6 answer would be:
say "{ 1, 3, 5, 7 ...^ *>100000 }"
The golfed version would be:say "{1,3...9 x 5}"
orsay "{1,3...99999}"
– Brad Gilbert b2gills – 2014-12-29T15:02:47.243Read this: http://codegolf.stackexchange.com/questions/2682/tips-for-golfing-in-javascript
– anatolyg – 2014-12-30T21:13:17.8631Did you teacher specify that only the odd numbers were to be printed? – Flygenring – 2015-01-09T02:16:53.653