var level = 1; var rollamt=Math.floor(Math.random() * 3)+5; console.log("---------------------") for (let i = 0; i < rollamt; i++) { let result = weightedRandom({"Energy":(0.15+level*0.008), "Cryptic Bundle":(0.02+level*0.002), "Key Bundle":(0.017+level*0.0015), "Common Crystal":(0.16-level*0.0115), "Uncommon Crystal":(0.04-level*0.005), "Rare Crystal":(0.01+level*0.002), "Legendary Crystal":(0.003+level*0.0004), "Common Att":(0.19-level*0.0272), "Uncommon Att":(0.058-level*0.008), "Rare Att":(0.013+level*0.0096), "Legendary Att":(0.004+level*0.001), "Tokens":(0.11+level*0.01), "Legendary Orb":(0.02+level*0.005), "Heroic Orb":(0.01+level*0.002), "Trinket Shards":(0.03+level*0.007), "Charity Booster":(0.04+level*0.002), "Click Boss":(0.08-level*0.01), "DCrate (Common)":(0.021+level*0.005), "DCrate (Rare)":(0.01+level*0.003), "DCrate (Expert)":(0.005+level*0.001), "Contraband":(0.002+level*0.0005), "Donor RU":(0.007+level*0.0017)}); if (result=="Energy"){ amount=Math.floor(Math.random() * ((84000+44000*level)-(36000+18000*level)+1))+(36000+18000*level); console.log("Energy: "+amount) } if (result=="Cryptic Bundle"){ console.log("Cryptic Bundle") } if (result=="Key Bundle"){ console.log("Key Bundle") } if (result=="Common Crystal"){ console.log("Common Crystal") } if (result=="Uncommon Crystal"){ console.log("Uncommon Crystal") } if (result=="Rare Crystal"){ console.log("Rare Crystal") } if (result=="Legendary Crystal"){ console.log("Legendary Crystal") } if (result=="Common Att"){ console.log("Common Att") } if (result=="Uncommon Att"){ console.log("Uncommon Att") } if (result=="Rare Att"){ console.log("Rare Att") } if (result=="Legendary Att"){ console.log("Legendary Att") } if (result=="Tokens"){ amount=Math.floor(Math.random() * ((700000+300000*level)-(360000+180000*level)+1))+(360000+180000*level); console.log("Tokens: "+amount) } if (result=="Legendary Orb"){ amount=Math.floor(Math.random() * ((18+8*level)-(10+4*level)+1))+(10+4*level); console.log("Legendary Orbs: "+amount) } if (result=="Heroic Orb"){ console.log("Heroic Orb") } if (result=="Trinket Shards"){ amount=Math.floor(Math.random() * ((20+6*level)-(8+4*level)+1))+(8+4*level); console.log("Trinket Shards: "+amount) } if (result=="Charity Booster"){ rollCharityBooster(); } if (result=="Click Boss"){ amount=Math.floor(Math.random() * ((6+2*level)-(3+1*level)+1))+(3+1*level); console.log("Click Bosses: "+amount) } if (result=="DCrate (Common)"){ console.log("DCrate (Common)") } if (result=="DCrate (Rare)"){ console.log("DCrate (Rare)") } if (result=="DCrate (Expert)"){ console.log("DCrate (Expert)") } if (result=="Contraband"){ console.log("Contraband") } if (result=="Donor RU"){ console.log("Donor Rankupgrade Paper") } } var level = 1; var rollamt=Math.floor(Math.random() * 4)+5; console.log("---------------------") for (let i = 0; i < rollamt; i++) { let result = weightedRandom({"Common Keys":(0.45-level*0.08), "Uncommon Keys":(0.2-level*0.02), "Rare Keys":(0.15+level*0.05), "Mythical Keys":(0.08+level*0.02), "Legendary Keys":(0.06+level*0.015), "Master Keys":(0.04+level*0.01), "Cryptic Keys":(0.02+level*0.005)}); if (result=="Common Keys"){ amount=Math.floor(Math.random() * ((20+8*level)-(12+5*level)+1))+(12+5*level); console.log("Common Keys: "+amount) } if (result=="Uncommon Keys"){ amount=Math.floor(Math.random() * ((17+7*level)-(11+5*level)+1))+(11+5*level); console.log("Uncommon Keys: "+amount) } if (result=="Rare Keys"){ amount=Math.floor(Math.random() * ((15+7*level)-(10+4*level)+1))+(10+4*level); console.log("Rare Keys: "+amount) } if (result=="Mythical Keys"){ amount=Math.floor(Math.random() * ((12+6*level)-(8+4*level)+1))+(8+4*level); console.log("Mythical Keys: "+amount) } if (result=="Legendary Keys"){ amount=Math.floor(Math.random() * ((10+5*level)-(6+3*level)+1))+(6+3*level); console.log("Legendary Keys: "+amount) } if (result=="Master Keys"){ amount=Math.floor(Math.random() * ((8+4*level)-(5+3*level)+1))+(5+3*level); console.log("Master Keys: "+amount) } if (result=="Cryptic Keys"){ amount=Math.floor(Math.random() * ((1+0.5*level)-(1+0.33*level)+1))+(1+0.33*level); console.log("Cryptic Keys: "+amount) } } console.log("---------------------") var level = 1; var rollamt=Math.floor(Math.random() * 4)+3; console.log("---------------------") for (let i = 0; i < rollamt; i++) { let result = weightedRandom({"Single Cryptic":(0.38-level*0.08), "Double Cryptic":(0.25-level*0.02), "Triple Cryptic":(0.13+level*0.05), "Quadruple Cryptic":(0.1+level*0.02), "Quintuple Cryptic":(0.07+level*0.015), "Sextuple Cryptic":(0.06+level*0.01)}); if (result=="Single Cryptic"){ amount=Math.floor(Math.random() * ((20+8*level)-(12+5*level)+1))+(12+5*level); console.log("Single Cryptics: "+amount) } if (result=="Double Cryptic"){ amount=Math.floor(Math.random() * ((13+7*level)-(8+5*level)+1))+(8+5*level); console.log("Double Cryptics: "+amount) } if (result=="Triple Cryptic"){ amount=Math.floor(Math.random() * ((11+6*level)-(5+4*level)+1))+(5+4*level); console.log("Triple Cryptics: "+amount) } if (result=="Quadruple Cryptic"){ amount=Math.floor(Math.random() * ((9+4*level)-(4+3*level)+1))+(4+3*level); console.log("Quadruple Cryptics: "+amount) } if (result=="Quintuple Cryptic"){ amount=Math.floor(Math.random() * ((7+3*level)-(3+2*level)+1))+(3+2*level); console.log("Quintuple Cryptics: "+amount) } if (result=="Sextuple Cryptic"){ amount=Math.floor(Math.random() * ((5+2*level)-(3+1*level)+1))+(3+1*level); console.log("Sextuple Cryptics: "+amount) } } console.log("---------------------") function weightedRandom(prob) { let i, sum=0, r=Math.random(); for (i in prob) { sum += prob[i]; if (r <= sum) return i; } } rollCharityBooster(); function rollCharityBooster(){ rng=Math.floor(Math.random() * (101)); if (rng<=65){ boost=Math.floor(Math.random() * (21)); xp=Math.floor(Math.random() * (3))+2; console.log("Common Charity Booster "+(1+boost/100)+"x / "+xp+"x XP") } if (rng<=80&&rng>65){ xp=Math.floor(Math.random() * (4))+3; boost=Math.floor(Math.random() * (31)); console.log("Uncommon Charity Booster "+(1.3+boost/100)+"x / "+xp+"x XP") } if (rng<=88&&rng>80){ xp=Math.floor(Math.random() * (6))+5; boost=Math.floor(Math.random() * (56)); console.log("Rare Charity Booster "+(1.7+boost/100)+"x / "+xp+"x XP") } if (rng<=94&&rng>88){ xp=Math.floor(Math.random() * (8))+10; boost=Math.floor(Math.random() * (81)); console.log("Epic Charity Booster "+(2.3+boost/100)+"x / "+xp+"x XP") } if (rng<=98&&rng>94){ xp=Math.floor(Math.random() * (14))+18; boost=Math.floor(Math.random() * (131)); console.log("Leg. Charity Booster "+(3.2+boost/100)+"x / "+xp+"x XP") } if (rng>98){ rng2=Math.floor(Math.random() * (101)); if(rng2<11){ xp=Math.floor(Math.random() * (66))+35; boost=Math.floor(Math.random() * (1110)); console.log("GODLY Charity Booster "+(14.1+boost/100)+"x / "+xp+"x XP") } if(rng2>10){ xp=Math.floor(Math.random() * (16))+25; boost=Math.floor(Math.random() * (381)); console.log("Extreme Charity Booster "+(5+boost/100)+"x / "+xp+"x XP") } } }
Write, Run & Share Javascript code online using OneCompiler's JS online compiler for free. It's one of the robust, feature-rich online compilers for Javascript language. Getting started with the OneCompiler's Javascript editor is easy and fast. The editor shows sample boilerplate code when you choose language as Javascript and start coding.
Javascript(JS) is a object-oriented programming language which adhere to ECMA Script Standards. Javascript is required to design the behaviour of the web pages.
var readline = require('readline');
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
terminal: false
});
rl.on('line', function(line){
console.log("Hello, " + line);
});
Keyword | Description | Scope |
---|---|---|
var | Var is used to declare variables(old way of declaring variables) | Function or global scope |
let | let is also used to declare variables(new way) | Global or block Scope |
const | const is used to declare const values. Once the value is assigned, it can not be modified | Global or block Scope |
let greetings = `Hello ${name}`
const msg = `
hello
world!
`
An array is a collection of items or values.
let arrayName = [value1, value2,..etc];
// or
let arrayName = new Array("value1","value2",..etc);
let mobiles = ["iPhone", "Samsung", "Pixel"];
// accessing an array
console.log(mobiles[0]);
// changing an array element
mobiles[3] = "Nokia";
Arrow Functions helps developers to write code in concise way, it’s introduced in ES6.
Arrow functions can be written in multiple ways. Below are couple of ways to use arrow function but it can be written in many other ways as well.
() => expression
const numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
const squaresOfEvenNumbers = numbers.filter(ele => ele % 2 == 0)
.map(ele => ele ** 2);
console.log(squaresOfEvenNumbers);
let [firstName, lastName] = ['Foo', 'Bar']
let {firstName, lastName} = {
firstName: 'Foo',
lastName: 'Bar'
}
const {
title,
firstName,
lastName,
...rest
} = record;
//Object spread
const post = {
...options,
type: "new"
}
//array spread
const users = [
...adminUsers,
...normalUsers
]
function greetings({ name = 'Foo' } = {}) { //Defaulting name to Foo
console.log(`Hello ${name}!`);
}
greet() // Hello Foo
greet({ name: 'Bar' }) // Hi Bar
IF is used to execute a block of code based on a condition.
if(condition){
// code
}
Else part is used to execute the block of code when the condition fails.
if(condition){
// code
} else {
// code
}
Switch is used to replace nested If-Else statements.
switch(condition){
case 'value1' :
//code
[break;]
case 'value2' :
//code
[break;]
.......
default :
//code
[break;]
}
For loop is used to iterate a set of statements based on a condition.
for(Initialization; Condition; Increment/decrement){
//code
}
While is also used to iterate a set of statements based on a condition. Usually while is preferred when number of iterations are not known in advance.
while (condition) {
// code
}
Do-while is also used to iterate a set of statements based on a condition. It is mostly used when you need to execute the statements atleast once.
do {
// code
} while (condition);
ES6 introduced classes along with OOPS concepts in JS. Class is similar to a function which you can think like kind of template which will get called when ever you initialize class.
class className {
constructor() { ... } //Mandatory Class method
method1() { ... }
method2() { ... }
...
}
class Mobile {
constructor(model) {
this.name = model;
}
}
mbl = new Mobile("iPhone");