Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

If/Else Statements Socket.io Client

Posted on 2013-12-14
1
Medium Priority
?
242 Views
Last Modified: 2013-12-14
I have been trying to add an If/Else statement to my Socket.io client for a personal project I've been working on. The end goal is to create a Bitcoin ticker with 2 values (oldPrice and newPrice) sent from the server. I would like to be able to change the styling and bg color depending on the values.

This is what I have to far:

var socket = io.connect('http://localhost:1000');

socket.on('newPrice', function(data){
   var newPrice = data.value  
});

socket.on('oldPrice', function(data){
   var oldPrice = data.value    
});

Open in new window


I would like to add this:

if (newPrice < oldPrice) {

            }else if (newPrice > oldPrice) {

            }

Open in new window


Thanks!
0
Comment
Question by:hallowz
1 Comment
 
LVL 44

Accepted Solution

by:
Rainer Jeschor earned 1500 total points
ID: 39718633
Hi,
I think you have to generate the variables "globally" like
var socket = io.connect('http://localhost:1000');
var newPrice = 0, oldPrice = 0;

socket.on('newPrice', function(data){
   newPrice = data.value  
});

socket.on('oldPrice', function(data){
   oldPrice = data.value    
});

Open in new window


Your compare should then be like
if (newPrice < oldPrice) {

            }else {

            }

Open in new window


HTH
Rainer
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question