Skip to content

Commit

Permalink
Create jsstuff.js
Browse files Browse the repository at this point in the history
  • Loading branch information
mcnole25 authored Jan 10, 2024
1 parent dd57547 commit a34266b
Showing 1 changed file with 136 additions and 0 deletions.
136 changes: 136 additions & 0 deletions jsstuff.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
class JSStuff {
getInfo() {
return {
id: 'jsstuff',
name: 'JS Stuff',
blocks: [
{
opcode: 'roundNearest',
blockType: Scratch.BlockType.REPORTER,
text: 'round [A] to the nearest [B]',
arguments: {
A: {
type: Scratch.ArgumentType.STRING,
defaultValue: '3.14'
},
B: {
type: Scratch.ArgumentType.STRING,
defaultValue: '0.1'
}
}
},
{
opcode: 'joinThree',
blockType: Scratch.BlockType.REPORTER,
text: 'join [A] [B] [C]',
arguments: {
A: {
type: Scratch.ArgumentType.STRING,
defaultValue: 'apple '
},
B: {
type: Scratch.ArgumentType.STRING,
defaultValue: 'banana '
},
C: {
type: Scratch.ArgumentType.STRING,
defaultValue: 'pear'
}
}
},
{
opcode: 'mathDropdown',
blockType: Scratch.BlockType.REPORTER,
text: '[A] of [B]',
arguments: {
A: {
type: Scratch.ArgumentType.STRING,
menu: 'MATH_MENU'
},
B: {
type: Scratch.ArgumentType.STRING
}
}
},
{
opcode: 'reverse',
blockType: Scratch.BlockType.REPORTER,
text: 'reverse [A]',
arguments: {
A: {
type: Scratch.ArgumentType.STRING,
defaultValue: 'apple'
}
}
},
{
opcode: 'oddOrEven',
blockType: Scratch.BlockType.BOOLEAN,
text: '[A] is [B] ?',
arguments: {
A: {
type: Scratch.ArgumentType.STRING,
},
B: {
type: Scratch.ArgumentType.STRING,
menu: 'ODD_OR_EVEN'
}
}
}
],
menus: {
MATH_MENU: {
acceptReporters: false,
items: [
{
text: 'sign',
value: 'sign'
},
{
text: 'sigmoid',
value: 'sigmoid'
}
]
},
ODD_OR_EVEN: {
acceptReporters: true,
items: [
{
text: 'odd',
value: 'odd'
},
{
text: 'even',
value: 'even'
}
]
}
}
};
}

roundNearest(args) {
return Math.round(args.A / args.B) * args.B;
}
joinThree(args) {
return args.A.concat(args.B.concat(args.C));
}
mathDropdown(args) {
if (args.A === 'sign') {
return Math.sign(args.B);
} else {
return 1 / (1 + Math.E ** -args.B);
}
}
reverse(args) {
return args.A.split('').reverse().join('');
}
oddOrEven(args) {
if (args.B === 'even') {
return Number.isInteger(args.A / 2);
} else {
return Number.isInteger(args.A / 2 + 0.5);
}
}
}
Scratch.extensions.register(new JSStuff());

0 comments on commit a34266b

Please sign in to comment.