Random Number generator

Excursionist
85 0 6

Hi,

I want to generate a number between 5 and 10 on my products page. Could you please help me?

Something like: "Only x people eligible." Where x is between 5 and 10. ty!

0 Likes
Highlighted
Astronaut
765 80 153

You can use javascript.

<div class="whole-sentence">Only <div class="some-div"></div> people eligible </div>

<script>

function getRandomInt(min, max) {
  return Math.floor(Math.random() * (max - min + 1)) + min;
  
}
var your_number = getRandomInt(5,10);

$('some-div').html(your_number);

</script>

 

If you'd like to make any edits to your store, please send me a personal message and we can discuss what you'd like to accomplish :D
0 Likes
Excursionist
85 0 6

ty Ninthony! where do I put it? I'm a newbie at coding but willing to learn! tyvm

0 Likes
Astronaut
765 80 153

You would put the <script></script>  section in the very bottom part of your product.liquid page. And the div's would have to go wherever you wanted your sentence to show up. Take in mind that this will generate a different number each time the page loads. I'm not sure what you're using it for. 

If you'd like to make any edits to your store, please send me a personal message and we can discuss what you'd like to accomplish :D
0 Likes
Excursionist
85 0 6

ty Ninthony. 

Understood the part about script></script>  

I want the actual sentence to just after the Add to Cart button on my product page. Which .liquid file should I open and where should I put the code: <div class="whole-sentence">Only <div class="some-div"></div> people eligible </div>

ty so much for helping!

0 Likes
Astronaut
765 80 153

You'll have to find your add to cart button on your product.liquid page. I can't tell you where to put it because I have no idea what your page looks like. Do you have a link? 

If you'd like to make any edits to your store, please send me a personal message and we can discuss what you'd like to accomplish :D
0 Likes
Shopify Expert
2000 82 1451

I've seen all kinds of techniques for trying to drive sales - some cool, others a bit dirty. Faking data is definitely in the dirtier side. Trust is one of the most important things to build with your customers and you're making the intentional choice to mislead them. Could be a winning strategy, but keep the negative impact in mind as well.

★ Winning Partner of the Build a Business competition. ★ http://freakdesign.com.au
1 Like