Last updated March 19th, 2019

What You'll Learn 🧠

➤   What the code block is and how it works

➤   Example applications of the code block

Code Block Overview

The code block accepts a popular programming language known as JavaScript. If you don't know how to code, that's alright! Thankfully, there's lots of resources we can use to integrate this block into our skill's logic. 



JavaScript Resources

  • W3Schools - good for learning JS syntax and supported functions
  • Stack Overflow - good for finding answers to specific questions (must specify that you're using JS in your search).

Beginner's Example

To store a random number from 0 - 100 in the {random_num} variable put this in your Code block:

random_num = Math.floor(Math.random() * 101); 

Declare 'random_num' as a variable on Voiceflow. Connect the Code block to a Speak block that states "The random number is {random_num}" and run your project on the Voiceflow test tool.



I copied this code from here. Easy stuff, right? 

Advanced Example

To get the current date in (yyyy/mm/dd) format put this in your code block:

var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1; //January is 0!
var yyyy = today.getFullYear();

if(dd<10) {
    dd = '0'+ dd
}

if(mm < 10) {
    mm = '0'+ mm
}

var todaysDate = yyyy + '-' + mm + '-' + dd;


Declare 'todaysDate' as a variable on Voiceflow. Connect the Code block to a Speak block that states "The current date is {todaysDate}" and run your project on the Voiceflow test tool.


I copied this code from here. The internet makes things so easy for us!

Still have questions? Be sure to post in our Forums to get fast answers!

Did this answer your question?