Error with Velo Tutorial

Question:
Hey everyone, I’m new to using Velo. I’m following their tutorial (Getting Started with Velo by Wix), but for some reason the expected out come isn’t working properly.

I’ve even tried simply copy pasting their code, and it’s not working.

Anybody able to make this work and help me out? Thanks!

Product:
Studio

What are you trying to achieve:
Make the tutorial code work

What have you already tried:
Asking ChatGPT, using the code provided in the tutorial, ensuring IDs are accurate

Additional information:
Also kind of new to coding in general, not an expert.

1 Like

Hey! Glad someone else is posting this, I’ve got the exact same issue. Experienced dev in other languages, new to Wix, just enabled Developer Mode for the first time today and tried to write some JS - nothing ran at all.

Tried copy-pasting simple code from YouTube tutorials, nothing. I even reduced it to a single console.log("Hello World") and tried it in the onReady of every page + masterPage, and nothing appeared in the log. No idea what’s going wrong.

1 Like

Update: even tried getting my own custom API key from the website mentioned in the tutorial (although the tutorial did not mention it was required to do so, thought I’d try) - nothing.

For reference, here’s my hello world:

// API Reference: https://www.wix.com/velo/reference/api-overview/introduction
// “Hello, World!” Example: https://learn-code.wix.com/en/article/hello-world

$w.onReady(function () {
    // To select an element by ID use: $w('#elementID')

    // Click 'Preview' to run your code
    console.log("Hello World");
});

I assume there’s some really dumb thing I haven’t done like install a package or something (it’s usually that!) but Google hasn’t turfed up any results.

1 Like

For such simple CODE → you don’t have to install anything.

So, for you beginners it is very important first to understand how Velo-Code works.

  1. You have a Wix-Site.
  2. Your Wix-Site has pages.
  3. Now you navigate onto one of your pages.
  4. DO NOT FORGET TO ACTIVATE THE CODE-MODE first (DEV-MODE).
  5. Now you see your page and the CODE-AREA.
  6. Every page has already a simple BASIC-CODE-SETUP like…
$w.onReady(()=> {
    ....
    ....
    ....
    ....
});

You can see this as the very STARTING-POINT of your page (except the IMPORTS, which you put on the very TOP of your pages).

Once you page is → READY ← (this is exactly, what the basic code is for), waiting for the page to be ready first before interacting with it.

Ok, let’s say, your PAGE is → READY ! Now you want to say → ‘Hello World’, like every code-beginner do (either directly on the page, or at least inside of the CONSOLE).

Since we are ongoing-PROGRAMMERS → we work with the console (ONLY), because this will become our best friend in the FUTURE.

Ho to use the CONSOLE ? There are 2-OPTIONS !

a) Using the CONSOLE directly inside of the Wix-Editor.
b) Using the console on your published LIVE-SITE in the BROWSER of your choice, for example —> Google-Chrome.

You press F12 and navigate to the----> CONSOLE. Now you can see in an additional console.window all outputs of your pages interactions and functions.

BACK TO YOUR PROVIDED CODE…

$w.onReady(function () {
    // To select an element by ID use: $w('#elementID')

    // Click 'Preview' to run your code
    console.log("Hello World");
});

We delete the → COMMENTS <— we do not need them yet…

$w.onReady(function () {
    console.log("Hello World");
});

We add some more code…

$w.onReady(function () { console.log('Page is ready...');
    console.log("Hello World");
});

Now, after publishing your site and opening it inside of a BROWSER of your choice, you navigate to the CONSOLE of your BROWSER and take a look onto the LOGs you got from your page.

Let us expand the code even more and add a TIME-DELAY, to create a TIME-DELAYED message to our CONSOLE…

$w.onReady(function () { console.log('Page is ready...');

    console.log("Hello World");

    setTimeOut(()=>{
        console.log("Hello World again, after 3-seconds !");
    },3000);
});

Check the outputs.

Now, you understand how all the process-flow is working —> Now you can dive into your futured ADVENTURE !!! HAPPY CODING !!!

Hey, thanks a lot for the explanation, but this isn’t helping my specific issue here. Specifically in my case, I followed a guide which is supposed to make a currency converter on the page. Here is that guide (from Wix themselves): Getting Started with Velo by Wix

The code they provide is on the bottom of that page.

What I can’t figure out is why nothing happens when I click the convert button (ID: calculateButton).

My code below in quotes (not sure how to make it looks nice in this forum, sorry for the formatting):

"import {getJSON} from ‘wix-fetch’;

const url = “https://api.exchangerate.host/convert”;

let currencyOptions = [
{“value”: “USD”, “label”: “US Dollars”},
{“value”: “EUR”, “label”: “Euros”},
{“value”: “JPY”, “label”: “Japanese Yen”},
];

$w.onReady(function () {
// Write your JavaScript here

// To select an element by ID use: $w('#elementID')

// Click 'Preview' to run your code

function populateDropdowns(){
    // Setting the dropdown options.
    $w("Dropdown").options = currencyOptions;
    // Setting the first dropdown option as the initial option.
    $w("Dropdown").selectedIndex = 0;
}

// Calculating the target amount.
function calculateCurrency() {
    // Initial amount
    let initialAmount = $w('#sourceAmount').value;
    // Original currency
    let sourceSymbol = $w('#sourceCurrency').value;
    // Target symbol
    let targetSymbol = $w('#targetCurrency').value;
    // Define the API key.
      let apiKey = '2e13c99ee0b5fd165338a828380b0e61';
    // Define the full url.
    let fullUrl = `${url}?from=${sourceSymbol}&to=${targetSymbol}`;

    let headers = new Headers();
    headers.append('X-Api-Key', apiKey);

    let requestOptions = {
        method: 'GET',
        headers: headers,
        redirect: 'follow'
    };

    // Call the wix-fetch API function to retrieve the JSON resource.
    getJSON(fullUrl, requestOptions)
        .then(json => {
            const result = initialAmount * json.info.rate;
            if (typeof result === 'number') {
                $w("#targetAmount").value = result.toString();
            } else {
                console.error("Unexpected result type:", result);
            }
        });
}

populateDropdowns();

$w('#calculateButton').onClick((event) => {
    calculateCurrency();
})

});"

I mean the above is literally exactly what I was doing, and it didn’t work! :smiley:

However the problem seems to have fixed itself, I came back this evening and the exact same code with zero changes is now working so it must have been something at Wix’s end.

Okay I’ve identified the exact cause in my situation. Typing new code and pressing Run/Preview does nothing, but if I refresh the page after typing the code and press Run/Preview it works. So it’s something to do with the code not getting updated or saved correctly.

(I at least have a workaround now, which is to refresh the page after making any code changes.)

1 Like

Have the exact same problem, came here to see if it’s been reported. Was surprised to see it hadn’t been.

After each change to the code I have to reload the entire editor to see the changes. Hopefully it gets fixed soon because working like this is not sustainable.

1 Like

@Wix —> another BUG found!

1 Like

I added a reply to my own thread but it got filtered for spam. Says a moderator will review the message; @Wix can you help me with that please?

This workaround doesn’t seem to work for me. You’re saying you refresh the page after writing your code, then click run and see it if works on the site? Or is it something else?

Yep that’s been working for me - write code, refresh page, hit Preview, code works fine (without the refresh the code doesn’t work). Could be a different problem for you then? :frowning:

Hmm yeah, looking into it further there appear to be issues with the API provided in the tutorial. Perhaps the info is outdated and the API no longer works for the purpose of the tutorial. Fiddled around with ChatGPT using a different API and it worked!