on 7a7bb80 help sign in
114 lines 22 kB history raw
1let letNumber = 1000;
2const constNumber = 10;
3var varNumber = -1234;
4const constNegativeFloat = -1.23;
5var tooMuch = Infinity;
6nothing = null;
7let listofthings = ["thing", 'thing2', `foo`, ["bar"]];
9// Simple comment
11/**
12* #########
13* Multiline
14* comment
15* #########
16*/
18let test;
19for (let i = 0; i < constNumber; i++) {
20 if (test) continue;
21 else test += 1; // random things
22}
24while(test < 100 && typeof test === "number") {
25 test = test > 30 ? test+5 : test+1;
26}
28function weatherSays(when=Date.now()) {
29 return "rain";
30}
32const thereAreClouds = true;
33const cloudsCount = 20;
35switch(weatherSays(Date.now())) {
36 case 'rain':
37 break;
38 case 'sun':
39 default:
40 break;
41}
43let rain = false;
44if ((thereAreClouds && cloudsCount >= 20) || weatherSays() === "rain") {
45 rain = false;
46} else if (thereAreClouds && weatherSays() == "rain") { // oh no, unsafe two equals checking!
47 rain = true;
48} else {
49 rain = !!cloudsCount;
50}
52class Forecast {
53 constructor(where, isGonnaRainA=true, isGonnaRainB=false, isGonnaRainC=false, ...randomArgs) {
54 this.station = {
55 location: [where.x, where.y, where.z],
56 surroundings: {
57 zoneA: {
58 location: [1, 2, 3],
59 isGonnaRain: isGonnaRainA
60 },
61 zoneB: {
62 location: [-1, 2, 2],
63 isGonnaRain: isGonnaRainB
64 },
65 zoneC: {
66 location: [-2, 0, 0],
67 isGonnaRainC: isGonnaRainC
68 },
69 }
70 };
71 }
72 
73 async getLocalPrevisions() {
74 const rainZones = [this.station.surroundings.zoneA.isGonnaRain, this.station.surroundings.zoneB.isGonnaRain, this.station.surroundings.zoneC.isGonnaRain];
75 return await rainZones.filter(z => !!z).length > (rainZones.length / 2);
76 }
77 
78 communicatePrevisions(isGonnaRain=undefined) {
79 if (isGonnaRain) console.log("Take the umbrella.");
80 }
81 
82 destroy() {
83 delete this.station;
84 }
85 
86 static startHiring() {
87 console.log("We're looking for weather presenters.");
88 console.log("A lot of presenters came. Hiring stops.");
89 }
90 
91 /* This forecasting station is magic. It can generate rain, but this method is secret because it's a generator function - nobody uses them! */
92 * generateRainInZoneC(clouds=[1, 2, 3]) {
93 this.station.surroundings.zoneC.isGonnaRain = true;
94 const makeRain = () => { return "raining!"; };
95 
96 yield clouds; // first, keeps clouds
97 do {
98 console.log(makeRain());
99 yield clouds.pop(); // then all clouds do rain
100 } while(clouds.length >= 1);
101 }
102}
104Forecast.startHiring();
105const forecasting = new Forecast([3, 3, 3]);
106(async() => {
107 const raining = forecasting.generateRainInZoneC();
108 raining.next();
109 forecasting.communicatePrevisions(await forecasting.getLocalPrevisions());
110 raining.next();
111 raining.next();
112 raining.return("stop!");
113 forecasting.destroy();
114})();