JavaScript

1989 readers
1 users here now

founded 1 year ago
MODERATORS
76
 
 

Hello, I am trying to learn JavaScript using morzilla developer network, are there any other good sources to learn and practice javascript.

77
5
submitted 10 months ago* (last edited 10 months ago) by [email protected] to c/[email protected]
 
 

I currently use Svelte in my main personal project but while enjoying it's relatively concise, declarative syntax, I don't really like how it's not always easy or even possible to do stuff without relying on shared state and I think that's bad. So I started looking into Elm, but it seems to require a significant portion of boilerplate and somewhat more procedural code, which surprised me, considering how Haskell is often notably more concise than C. Is there anything that is somewhat like Elm, i.e. functional, but without being overly verbose?

Edit: I'd also prefer bundle sizes no larger or marginally larger than with Svelte and decent noscript support, at least on par with Vue or HTMX.

78
 
 

I am part of a team that runs a small wiki for a game 99% of the population never heard of (don't ask me what it is), so I wanted to make a discord bot that used our API to pull info quickly, how it works is you do /search name:[enter name of item] and you get a list of, at most, the top 5 search results with emojis at the bottom to react with, then the bot should spit out another embed message with item description and stats, etc. The issue is that for the life of me, I can't seem to make the bot recognize what emoji the user has selected, as it always just returns '0' emojis selected. I am noob at JS, plz help

Here is what I got: `

async execute(interaction) {
    const query = interaction.options.getString("name");

    let itemData;

    try {
        // Get data from api
        const itemAPIList = await fetch(
            `the link for our api, not important q=${query}`
        ).then((res) => res.json());
        itemData = itemAPIList.data;

        const emojis = ["1️⃣", "2️⃣", "3️⃣", "4️⃣", "5️⃣"];

        // Check if itemData from api is not empty
        if (itemData.length > 0) {
            // Create the embed message
            const itemEmbed = new EmbedBuilder()
                .setColor(0x00ff80)
                .setDescription(
                    "React with the corresponding emoji to select an item"
                );
            // List out the top 5 results from api with an emoji next to it
            for (let i = 0; i < 5 && i < itemData.length; i++) {
                itemEmbed.addFields({
                    name: `${emojis[i]}: ${itemData[i].name}`,
                    value: " ",
                });
            }
            // Sends the embedded message
            const sentItemList = await interaction
                .reply({
                    embeds: [itemEmbed],
                    fetchReply: true,
                })
                .then(async (itemListMsg) => {
                    // Reacts to the message with correct number of emoji numbers
                    for (
                        let i = 0;
                        i < emojis.length && i < itemData.length;
                        i++
                    ) {
                        await itemListMsg.react(emojis[i]);
                    }

                    // Filter for checking if emoji and user are correct
                    const collectorFilter = (reaction, user) => {
                        return (
                            emojis.includes(reaction.emoji.name) &&
                            user.id === interaction.user.id
                        );
                    };

                    const collector =
                        await itemListMsg.createReactionCollector({
                            filter: collectorFilter,
                            time: 5000,
                        });

                    collector.on("collect", (reaction, user) => {
                        console.log(
                            `Collected ${reaction.emoji.name} from ${user.tag}`
                        );
                    });

                    collector.on("end", (collected) => {
                        console.log(`Collected ${collected.size} items`);
                    });
                });
        }

`

79
80
81
 
 

Title. I'm trying to compile this but I can't seem to do so with node.js.

Thanks in advance.

82
83
84
18
State of JavaScript 2023 (survey.devographics.com)
submitted 11 months ago by [email protected] to c/[email protected]
85
86
87
88
 
 

Hello!

I am pleased to announce a new version of my Understanding JavaScript RegExp ebook. This book will help you learn JavaScript Regular Expressions step-by-step from beginner to advanced levels with hundreds of examples and exercises.

Links:

I would highly appreciate it if you'd let me know how you felt about this book. It could be anything from a simple thank you, pointing out a typo, mistakes in code snippets, which aspects of the book worked for you (or didn't!) and so on. Reader feedback is essential and especially so for self-published authors.

Happy learning :)

89
28
submitted 1 year ago* (last edited 11 months ago) by [email protected] to c/[email protected]
 
 

The next minor release of ESLint will deprecate core formatting rules. [The dev team] recommends you use a source code formatter [Prettier, dprint] instead.

90
91
 
 

I am currently trying to learn Javascript and am getting hung up trying to understand Regex. Does anyone have any good resources or recommendations for me?

92
93
94
95
 
 

Introducing Deno Queues - zero config, scalable messaging with a guaranteed at-least-once delivery. This new primitive builds on the foundation set by Deno KV, and is available today in the Deno JavaScript runtime and Deno Deploy.

96
97
98
99
 
 

This is a follow up to my previous article on how to get more TypeScript benefits in your JavaScript. This goes into how to add types using JSDoc or TypeScript declaration files.

100
view more: ‹ prev next ›