Hey forum users!
I need some assistance with a random number program. The RNG itself is fine, but I can’t figure out a way to use an if else statement to output “You Win” if the number is greater than .5 and “You Lose” if the number is less.
My current HTML schema is:
RNG
Welcome to Meteor!
{{> hello}}
Click
Your number is {{number}}
{{word}}
And my current JS schema is:
if (Meteor.isClient) {
// counter starts at 0
Session.setDefault(‘number’, Random.fraction());
Session.setDefault(‘word’, “”);
Template.hello.helpers({
number: function () {
return Session.get(‘number’);
}
});
Template.hello.helpers({
word: function () {
return Session.get(‘word’);
}
});
Template.hello.events({
‘click button’: function () {
// increment the counter when button is clicked
Session.set(“number”, 0+Random.fraction());
}
});
Template.hello.events({
‘click button’: function () {
// This is where I want the If Else
Session.set(“word”, 3);
}
});
}
if (Meteor.isServer) {
Meteor.startup(function () {
// code to run on server at startup
});
}
And the output is:
I am extremely new to coding so please use dumbed down words if possible.
Assistance would be greatly appreciated. Also, if anyone sees any way I can make this program more efficient I would like to hear it.
I don’t really understand that very well , when I said i was new i meant really new. Is there anyway you can explain that in simpler terms and also, how would i output my result of “You win” in the body?
It would probably be easier for me to write a small meteor app for you does want you want it to do. I’m pretty busy, but if you let me do it over the weekend I don’t mind helping you.
Can you explain what you want the app to do. A simple user story, if you don’t know already in programming, we try to group around the functionality around a simple story explaining what the end result is. It’s easier than trying to guess what you are doing with code (especially since you are new to programming).
As a user I should be shown a menu that shows me a word. When I Guess the word… yadda ya.
I was beginner in programming languages about 12 years ago too. Welcome here
Here’s a really quick example (runnable app here):
a) meteor create win-lose
b) meteor add reactive-var
c) Replace the contents of win-lose.html with:
<head>
<title>Win or Lose?</title>
</head>
<body>
<h1>Win or Lose?</h1>
<p>Click the button - if your result is greater than 0.5, you win!</p>
<button>Go!</button>
<p>
Result: {{result}} <strong>{{winOrLose}}</strong>
</p>
</body>
That would be awesome! I’m actually attempting to create a small virtual currency gambling site for a game called EVE. I’m just learning the basics RN so it won’t be set up for a long time. What i actually want to do is have a gambling program that has you enter a value that you want to wager, then if you win it pays back 1.95X what you wagered. If you lose you just lose the money you wagered.