DEV Community

Cover image for One Way to Cheat Wordle using Javascript
ozboware
ozboware

Posted on • Updated on

One Way to Cheat Wordle using Javascript

After creating my own version of Wordle I took a look at the code behind the original Wordle game to check for similarities and found that it's pretty easy to cheat the game and get not only the word of the day, but every word for the next 5 years. Now, the simplest way to cheat is to just look at the script, but the dev in me just wanted to do more, so I created a function that will push an alert to the screen showing the player the word of the day. It's a simple enough function, you can either paste it in the console (F12, click console, paste and then enter), or you could use it in a browser extension and have the alert each time you go onto the page, you could possibly even wrap it up in a .exe file and run it locally.

So the code is

let date = new Date();
let dayNames = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
let dayName = dayNames[date.getDay()];
let day = date.getDate();
let month = date.getMonth() + 1;
let year = date.getFullYear();
let today = month + "/" + day + "/" + year;
let startDate = new Date("06/19/2021");
let endDate = new Date(today);
let days = Math.floor((endDate.getTime() - startDate.getTime()) / (1000 * 60 * 60 * 24));
fetch ("https://www.nytimes.com/games/wordle/main.4951a4aa.js")
    .then(x => x.text())
    .then(y => {
        let wordArray = y.slice(y.indexOf('var Ma='), y.indexOf(',Oa='))
            .replace('var Ma=', '')
            .replace('[', '')
            .replace(']', '')
            .replace(/"/g, '')
            .split(',');
        alert('The word for today (' + dayName + ' ' + day + '/' + month + '/' + year + ') is ' + wordArray[days].toUpperCase());
    });
Enter fullscreen mode Exit fullscreen mode

go to the Wordle screen, paste that code into the console, submit it and an alert will pop up telling you the wordle of the day or something like

Wordle cheat demonstration

Top comments (1)

Collapse
 
dcromley profile image
Dave Cromley

Wow! There are 2 arrays of words: Ma (.length=2309) and Oa (.length=10,638). I would think that Ma would be potential answers and Oa would be accepted guesses? After 6+ years, they could shuffle and reuse Ma.