Random Issues
This seems bad:
function getValue() {
var num = Math.random();
if(num < 0.2) {
this.card = '<i class="fa fa-anchor"></i>';
}
if(0.2 > num < 0.4 ) {
this.card = '<i class="fa fa-heart"></i>';
}
if(0.4 > num < 0.6){
this.card = '<i class="fa fa-lemon-o"></i>';
}
if(0.6 > num < 1){
this.card = '<i class="fa fa-car"></i>';
}
}
When called repeatedly by this and similar:
value1 = new getValue();
I'm no Javascript expert, but I think you could improve performance by generating a large number of random slot machine sequences when the program starts, rather than calling Math.random()
repeatedly as the program is running. Maybe the performance gain is not that important, but I think it is worth mentioning. Also, when you start thinking about generating a large number of sequences, you could think about ways to manipulate the results, potentially for gameplay reasons (such as a power-up increases the odds of a certain value).
This may not apply so much to Javascript, but definitely in other languages calling the equivalent of Random()
can be costly.
I looked up Math.random()
and it appears that there may be better options for better random generation. See this Stack Overflow answer about Javascript randomness Javascript randomness.
Random Issues
This seems bad:
function getValue() {
var num = Math.random();
if(num < 0.2) {
this.card = '<i class="fa fa-anchor"></i>';
}
if(0.2 > num < 0.4 ) {
this.card = '<i class="fa fa-heart"></i>';
}
if(0.4 > num < 0.6){
this.card = '<i class="fa fa-lemon-o"></i>';
}
if(0.6 > num < 1){
this.card = '<i class="fa fa-car"></i>';
}
}
When called repeatedly by this and similar:
value1 = new getValue();
I'm no Javascript expert, but I think you could improve performance by generating a large number of random slot machine sequences when the program starts, rather than calling Math.random()
repeatedly as the program is running. Maybe the performance gain is not that important, but I think it is worth mentioning. Also, when you start thinking about generating a large number of sequences, you could think about ways to manipulate the results, potentially for gameplay reasons (such as a power-up increases the odds of a certain value).
This may not apply so much to Javascript, but definitely in other languages calling the equivalent of Random()
can be costly.
I looked up Math.random()
and it appears that there may be better options for better random generation. See this Stack Overflow answer about Javascript randomness.
Random Issues
This seems bad:
function getValue() {
var num = Math.random();
if(num < 0.2) {
this.card = '<i class="fa fa-anchor"></i>';
}
if(0.2 > num < 0.4 ) {
this.card = '<i class="fa fa-heart"></i>';
}
if(0.4 > num < 0.6){
this.card = '<i class="fa fa-lemon-o"></i>';
}
if(0.6 > num < 1){
this.card = '<i class="fa fa-car"></i>';
}
}
When called repeatedly by this and similar:
value1 = new getValue();
I'm no Javascript expert, but I think you could improve performance by generating a large number of random slot machine sequences when the program starts, rather than calling Math.random()
repeatedly as the program is running. Maybe the performance gain is not that important, but I think it is worth mentioning. Also, when you start thinking about generating a large number of sequences, you could think about ways to manipulate the results, potentially for gameplay reasons (such as a power-up increases the odds of a certain value).
This may not apply so much to Javascript, but definitely in other languages calling the equivalent of Random()
can be costly.
I looked up Math.random()
and it appears that there may be better options for better random generation. See this Stack Overflow answer about Javascript randomness.
Random Issues
This seems bad:
function getValue() {
var num = Math.random();
if(num < 0.2) {
this.card = '<i class="fa fa-anchor"></i>';
}
if(0.2 > num < 0.4 ) {
this.card = '<i class="fa fa-heart"></i>';
}
if(0.4 > num < 0.6){
this.card = '<i class="fa fa-lemon-o"></i>';
}
if(0.6 > num < 1){
this.card = '<i class="fa fa-car"></i>';
}
}
When called repeatedly by this and similar:
value1 = new getValue();
I'm no Javascript expert, but I think you could dramatically improve performance by generating a large number of random slot machine sequences when the program starts, rather than creating a newcalling RandomMath.random()
object repeatedly as the program is running. Maybe the performance gain is not that important, but I think it is worth mentioning. Also, when you start thinking about generating a large number of sequences, you could think about ways to manipulate the results, potentially for gameplay reasons (such as a power-up increases the odds of a certain value).
This may not apply so much to Javascript, but definitely in other languages calling the equivalent of Random()
can be costly.
I looked up Math.random()
and it appears that there may be better options for better random generation. See this Stack Overflow answer about Javascript randomness .
Overall the code is good and clean and easy to understand. It seems to run really well. Your code might be more robust if you used strict mode to catch type errors that may arise if you try to extend the code further. You may want to consider using the new Javascript array syntax also if you are not already.
Random Issues
This seems bad:
function getValue() {
var num = Math.random();
if(num < 0.2) {
this.card = '<i class="fa fa-anchor"></i>';
}
if(0.2 > num < 0.4 ) {
this.card = '<i class="fa fa-heart"></i>';
}
if(0.4 > num < 0.6){
this.card = '<i class="fa fa-lemon-o"></i>';
}
if(0.6 > num < 1){
this.card = '<i class="fa fa-car"></i>';
}
}
When called repeatedly by this and similar:
value1 = new getValue();
I'm no Javascript expert, but I think you could dramatically improve performance by generating a large number of random slot machine sequences when the program starts, rather than creating a new Random()
object repeatedly as the program is running. Maybe the performance gain is not that important, but I think it is worth mentioning.
I looked up Math.random()
and it appears that there may be better options. See this Stack Overflow answer about Javascript randomness .
Overall the code is good and clean and easy to understand. It seems to run really well. Your code might be more robust if you used strict mode to catch type errors that may arise if you try to extend the code further. You may want to consider using the new Javascript array syntax also if you are not already.
Random Issues
This seems bad:
function getValue() {
var num = Math.random();
if(num < 0.2) {
this.card = '<i class="fa fa-anchor"></i>';
}
if(0.2 > num < 0.4 ) {
this.card = '<i class="fa fa-heart"></i>';
}
if(0.4 > num < 0.6){
this.card = '<i class="fa fa-lemon-o"></i>';
}
if(0.6 > num < 1){
this.card = '<i class="fa fa-car"></i>';
}
}
When called repeatedly by this and similar:
value1 = new getValue();
I'm no Javascript expert, but I think you could improve performance by generating a large number of random slot machine sequences when the program starts, rather than calling Math.random()
repeatedly as the program is running. Maybe the performance gain is not that important, but I think it is worth mentioning. Also, when you start thinking about generating a large number of sequences, you could think about ways to manipulate the results, potentially for gameplay reasons (such as a power-up increases the odds of a certain value).
This may not apply so much to Javascript, but definitely in other languages calling the equivalent of Random()
can be costly.
I looked up Math.random()
and it appears that there may be better options for better random generation. See this Stack Overflow answer about Javascript randomness.
Random Issues
This seems bad:
function getValue() {
var num = Math.random();
if(num < 0.2) {
this.card = '<i class="fa fa-anchor"></i>';
}
if(0.2 > num < 0.4 ) {
this.card = '<i class="fa fa-heart"></i>';
}
if(0.4 > num < 0.6){
this.card = '<i class="fa fa-lemon-o"></i>';
}
if(0.6 > num < 1){
this.card = '<i class="fa fa-car"></i>';
}
}
When called repeatedly by this and similar:
value1 = new getValue();
I'm no Javascript expert, but I think you could dramatically improve performance by generating a large number of random slot machine sequences when the program starts, rather than creating a new Random()
object repeatedly as the program is running. Maybe the performance gain is not that important, but I think it is worth mentioning.
I looked up Math.random()
and it appears that there may be better options. See this Stack Overflow answer about Javascript randomness.
I could make a comment about the comments in this code:
if(++spins < 50) {
// set a new, slightly longer interval for the next update. Makes it seem like the wheels are slowing down
setTimeout(update, 10 + spins * 2);
} else {
// re-enable the button
button.prop("disabled", false);
}
I think the first comment is an example of a good comment. It quickly explains some difficult to understand code that follows, and makes the magic number 50 easier to stomach. If you ever come back to this code, you will be able to understand it.
The second comment, however, is a bad comment. It says re-enable the button, yet "disabled"
and false
are the arguments. Is the comment wrong? It seems to contradict the line of code that follows. Probably better to omit the comment completely and let the logic of the code speak for itself.
Overall the code is good and clean and easy to understand. It seems to run really well. Your code might be more robust if you used strict mode to catch type errors that may arise if you try to extend the code further. You may want to consider using the new Javascript array syntax also if you are not already.
Random Issues
This seems bad:
function getValue() {
var num = Math.random();
if(num < 0.2) {
this.card = '<i class="fa fa-anchor"></i>';
}
if(0.2 > num < 0.4 ) {
this.card = '<i class="fa fa-heart"></i>';
}
if(0.4 > num < 0.6){
this.card = '<i class="fa fa-lemon-o"></i>';
}
if(0.6 > num < 1){
this.card = '<i class="fa fa-car"></i>';
}
}
When called repeatedly by this and similar:
value1 = new getValue();
I'm no Javascript expert, but I think you could dramatically improve performance by generating a large number of random slot machine sequences when the program starts, rather than creating a new Random()
object repeatedly as the program is running. Maybe the performance gain is not that important, but I think it is worth mentioning.
I looked up Math.random()
and it appears that there may be better options. See this Stack Overflow answer about Javascript randomness.
I could make a comment about the comments in this code:
if(++spins < 50) {
// set a new, slightly longer interval for the next update. Makes it seem like the wheels are slowing down
setTimeout(update, 10 + spins * 2);
} else {
// re-enable the button
button.prop("disabled", false);
}
I think the first comment is an example of a good comment. It quickly explains some difficult to understand code that follows, and makes the magic number 50 easier to stomach. If you ever come back to this code, you will be able to understand it.
The second comment, however, is a bad comment. It says re-enable the button, yet "disabled"
and false
are the arguments. Is the comment wrong? It seems to contradict the line of code that follows. Probably better to omit the comment completely and let the logic of the code speak for itself.
Overall the code is good and clean and easy to understand. It seems to run really well. Your code might be more robust if you used strict mode to catch type errors that may arise if you try to extend the code further. You may want to consider using the new Javascript array syntax also if you are not already.
Random Issues
This seems bad:
function getValue() {
var num = Math.random();
if(num < 0.2) {
this.card = '<i class="fa fa-anchor"></i>';
}
if(0.2 > num < 0.4 ) {
this.card = '<i class="fa fa-heart"></i>';
}
if(0.4 > num < 0.6){
this.card = '<i class="fa fa-lemon-o"></i>';
}
if(0.6 > num < 1){
this.card = '<i class="fa fa-car"></i>';
}
}
When called repeatedly by this and similar:
value1 = new getValue();
I'm no Javascript expert, but I think you could dramatically improve performance by generating a large number of random slot machine sequences when the program starts, rather than creating a new Random()
object repeatedly as the program is running. Maybe the performance gain is not that important, but I think it is worth mentioning.
I looked up Math.random()
and it appears that there may be better options. See this Stack Overflow answer about Javascript randomness.
Overall the code is good and clean and easy to understand. It seems to run really well. Your code might be more robust if you used strict mode to catch type errors that may arise if you try to extend the code further. You may want to consider using the new Javascript array syntax also if you are not already.