Spin Your Dreidel! Day 1 of the #25DaysOfServerless Challenge
Tags: javascript, azure, serverless, 25daysofserverless
Published: 2019-12-02 14:33:21

---
title: Spin Your Dreidel! Day 1 of the #25DaysOfServerless Challenge
published: true
description: Let's start with a very simple challenge: create a function to spin a dreidel
tags: JavaScript, Azure, Serverless, 25DaysOfServerless
cover_image: https://thepracticaldev.s3.amazonaws.com/i/s32bza5uuuut56qlqvym.png
---

This article is part of [#25DaysOfServerless](http://aka.ms/25daysofserverless). New challenges will be published every day from Microsoft Cloud Advocates throughout the month of December. Find out more about how Microsoft Azure enables your [Serverless functions](https://docs.microsoft.com/azure/azure-functions/?WT.mc_id=25days_devto-blog-jelooper). 

---

So, an evil grinch has stolen all the servers in the world, and we have to visit many countries to set things right! You can spin up a serverless function in Visual Studio Code almost as fast as you can win all your big brother's gelt. Now you're in Tel Aviv, Israel, and you find that all the dreidels, and any servers having to do with them, are missing! Your task? Save Hanukkah! Build a serverless function to spin a dreidel for you.

![dreidel](https://media.giphy.com/media/uhJpTtpVfT9cs/giphy.gif)

This is really easy in Azure. Build your Azure function using Visual Studio Code with the Azure Functions Extension installed. Scaffold the function using the tooling (click the lightning bolt to create a new function) and then click the 'bug' icon to run it. Hint: there are four possible dreidel values you can spin.

## Tips

A little bit of JavaScript would do the job in `index.js`:

```javascript
module.exports = async function (context) {  
    // נ (Nun), ג (Gimmel), ה (Hay), and ש (Shin)
    var num = Math.floor(Math.random() * 3);
    var values = ['ג','ה','ש','נ']
        context.res = {
            body: values[num]
        };
   
};
```

If you run the API endpoint that you just created with your function in a browser, you'll see a random value appear. You can publish this as a serverless function and save the family party! Extra latkes for you!

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/wwwsud1cuketm9zgt0f4.png)

## Running a solution

Open the [spin-the-dreidel](https://github.com/jlooper/spin-the-dreidel) folder in Visual Studio Code and run it locally using the debug tool in VS Code. You'll be able to see the randomly-spun dreidel value in the browser.

Want to submit your solution to this challenge? Build a solution locally and then [PR this repo](https://github.com/microsoft/25-days-of-serverless/pulls). If your solution doesn't involve code you can record a short video and submit it as a PR to the same repo. Make sure to tell us which challenge the solution is for. We're excited to see what you build! Do you have comments or questions? Add them to the comments area below.

---

> Did you know? Dreidel-spinning rules include: 

> a) Nun means “nisht” or “nothing.” The player does nothing.

> b) Gimel  means “gantz” or “everything.” The player gets everything in the pot.

> c) Hey means “halb” or “half.” The player gets half of the pot. (If there is an odd number of pieces in the pot, the player takes half of the total plus one).

> d) Shin (outside of Israel) means “shtel” or “put in.” Peh (in Israel) also means “put in.” The player adds a game piece to the pot.

Visit [MyJewishLearning](https://www.myjewishlearning.com/article/how-to-play-dreidel/) for all the rules.

---

Want to submit your solution to this challenge? Build a solution locally and then [submit an issue](https://github.com/microsoft/25-days-of-serverless/issues/new?assignees=&labels=challenge-submission&template=challenge-solution-submission.md&title=%5BCHALLENGE+SUBMISSION%5D+). If your solution doesn't involve code you can record a short video and submit it as a link in the issue desccription. Make sure to tell us which challenge the solution is for. We're excited to see what you build! Do you have comments or questions? Add them to the comments area below.

<hr/>
Watch for surprises all during December as we celebrate 25 Days of Serverless. Stay tuned here on dev.to as we feature challenges and solutions! Sign up for a [free account on Azure](https://azure.microsoft.com/free/?WT.mc_id=25days_devto-blog-jelooper) to get ready for the challenges!