|
Created a loop to loop through an array based on the values from the dice roll. Trying to get all the possible scores for a yahtzee game. so far I have it working to that it does add the scores based on the roll example1
I also have it working so that it does not continue to add the score if the a certain die is selected
However my issue is that it keeps increasing the score instead of starting over on subsequent rolls example2
<pre>$(document).ready(function(){
var die1=$('.die1');
var die2=$('.die2');
var die3=$('.die3');
var die4=$('.die4');
var die5=$('.die5');
var turns=3;
var dice;
var dice_value = new Array(5);
var ones=0;
var twos=0;
var threes=0;
var fours=0;
var fives=0;
var sixes=0;
var die;
function roll(die,i){
rando = Math.floor(Math.random()*6)+1;
die.html("<img src=images/die"+rando+".png>");
die.find('img').attr('class', rando);
dice_value[i]=rando;
$('img').height(50);
};
$('.die').click(function(){
$(this).toggleClass('selected');
});
$('.button').click(function(){
for(i=0; i<=turns; turns--){
if(turns>0){
dice =[die1,die2,die3,die4,die5];
for(i=0; i<dice.length;i++){
if (!dice[i].hasClass('selected')){
roll(dice[i],i);
die= dice[i].find('img').attr('class');
}
}
}
else{
$('.warning').html('Pick a category!');
}
}
for(var i=0; i< dice_value.length;i++){
if(!dice[i].hasClass('selected') && turns > 0){
if( dice_value[i] == 1){
ones= ones+1;
$('.aceScore').html(ones);
}
if( dice_value[i] == 2){
twos= twos+2;
$('.twoScore').html(twos);
}
if( dice_value[i] == 3){
threes= threes+3;
$('.threeScore').html(threes);
}
if( dice_value[i] == 4){
fours= fours+4;
$('.fourScore').html(fours);
}
if( dice_value[i] == 5){
fives= fives+5;
$('.fiveScore').html(fives);
}
if( dice_value[i] == 6){
sixes= sixes+6;
$('.sixScore').html(sixes);
}
}
}
});
console.log(ones);
console.log(twos);
console.log(threes);
console.log(fours);
console.log(fives);
console.log(sixes);
});
<pre lang="HTML"><pre><table border="1" height='200' >
<tr>
<th colspan="3">Upper Section</th>
</tr>
<tr>
<td>Aces</td>
<td>Sum of all the ones</td>
<td class="score aceScore"></td>
</tr>
<tr>
<td>Twos</td>
<td>Sum of all the twos</td>
<td class="score twoScore"></td>
</tr>
<tr>
<td>Threes</td>
<td>Sum of all the threes</td>
<td class="score threeScore"></td>
</tr>
<tr>
<td>Fours</td>
<td>Sum of all the fours</td>
<td class="score fourScore"></td>
</tr>
<tr>
<td>Fives</td>
<td>Sum of all the fives</td>
<td class="score fiveScore"></td>
</tr>
<tr>
<td>Sixes</td>
<td>Sum of all the sixes</td>
<td class="score sixScore"></td>
</tr>
<tr>
<td colspan ='2'>Total</td>
<td class="totalScore"></td>
</tr>
<tr>
<td>Bonus</td>
<td>Score 35 </td>
<td class="bonus"></td>
</tr>
<tr>
<td colspan ='2'>Upper Total</td>
<td class="upperScore"></td>
</tr>
<tr>
<th colspan="3">Lower Section</th>
</tr>
<tr>
<td>3 of a Kind</td>
<td>SUm of all dice</td>
<td class="three_of_kind"></td>
</tr>
<tr>
<td>4 of a kind</td>
<td>Sum of all dice</td>
<td class="four_of_kind"></td>
</tr>
<tr>
<td>Full House</td>
<td>Score 35</td>
<td class="fullhouse"></td>
</tr>
<tr>
<td>sm. straight</td>
<td>Score 30</td>
<td class="sm"></td>
</tr>
<tr>
<td>lg. Straight</td>
<td>score 40</td>
<td class="lg"></td>
</tr>
<tr>
<td>Yahtzee</td>
<td>Score yatzee</td>
<td class="yatzee"></td>
</tr>
<tr>
<td>Chance</td>
<td>sum of all dice</td>
<td class="chance"></td>
</tr>
<tr>
<td colspan ='2'>Lower Total</td>
<td class="lowerScore"></td>
</tr>
<tr>
<td colspan ='2'>Upper Total</td>
<td class="UpperScore"></td>
</tr>
<tr>
<td colspan ='2'>Combined Total</td>
<td class="combinedScore"></td>
</tr>
<section class="dice">
<div class="die die1"></div>
<div class="die die2"></div>
<div class="die die3"></div>
<div class="die die4"></div>
<div class="die die5"></div>
</section>
<button class="button">ROll</button>
</table>
</div> <!-- board div -->
</body>
</html>
|
|
|
|
|
You just need to reset all the counters to zero before each throw.
|
|
|
|
|
when i do that i doesnt add the score to the dice that I have selected to keep.
|
|
|
|
|
Then you need to keep those scores separately also. Think about how you actually play Yahtzee, and what you need to do before and after each throw.
|
|
|
|
|
$(document).ready(function () {
debugger;
if (window.location.href.toLowerCase = "https: Pages/HomePage.aspx") {
test.makeSharePointReady1();
}
I am trying to redirect to another site (say www.google.com) from a SharePoint site.
|
|
|
|
|
A very simple and quick fix will be to change the = operator, to == operator.
if (window.location.href.toLowerCase == "https: Pages/HomePage.aspx") {
"=" is used to assign the value, and "==" is used to test equality. Also, once converted to lowerCase, there is no sense in having "Page/HomePage" in caps, they will also be in lower format. Anyways, just see if that works otherwise, change them to lower case as well.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
toLowerCase is also a method so you need (). Also, lowercase your text that you are comparing to.
if (window.location.href.toLowerCase() == "https://pages/homepage.aspx") {
There are two kinds of people in the world: those who can extrapolate from incomplete data.
There are only 10 types of people in the world, those who understand binary and those who don't.
modified 10-Feb-17 11:05am.
|
|
|
|
|
Except that a lower-case string will never be equal to a string that contains upper-case characters.
Also, the protocol is missing the "//", and the server name is missing.
But apart from that...
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Richard Deeming wrote: Except that a lower-case string will never be equal to a string that contains upper-case characters. Ya, I didn't get that far into it. I had read the previous answer and noticed they missed that point. I guess I should have kept on looking.
There are two kinds of people in the world: those who can extrapolate from incomplete data.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
exactly
|
|
|
|
|
The location.href will return the full URL, including the server name. The string you're trying to compare it to does not contain the server name, and is missing the "//" from the protocol. Even if you make that string lower-case, it's never going to match the full URL.
Assuming you only want to match the path, use the pathname property instead of the href property:
if (window.location.pathname.toLowerCase() == "/pages/homepage.aspx") {
...
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I don't know where the crap characters before the full names are coming from...
1211;#Doe Doe, John;#1238;#Doe, John
Can someone show the code on how to clean or ltrim then separate each full name with semi-colon
This is part of the code to show the names where "employee" = full name.
Var employee = "";
if (ListName == "Award - Unit")
{
employee = rows[i].getAttribute('Nominee');
};
str+='<tr><td class=leftcol valign=top><font size="+2">Employee</font></td><td class=rightcol><font size="+2">' + employee + '</font></td></tr>';
|
|
|
|
|
|
is the data coming from sharepoint?
|
|
|
|
|
I'm thinking of using the browser BSON parser with a custom OWIN middleware that will pass queries directly to a Mongo instance for searches, and to WebAPI for processing.
Does anyone have any experience using this as a data transmission system? Primarily I'm curious as to any serious pitfalls that I might be overlooking, particularly with the browser BSON parser.
Edit: This guy GitHub - mongodb/js-bson: BSON Parser for node and browser
"There are three kinds of lies: lies, damned lies and statistics."
- Benjamin Disraeli
|
|
|
|
|
I'm trying to auto populate the value of a retirement date field by using a DOB (date of birth) value and adding 66 years onto this value.
but it's not working at the moment.
it's just returning the same value as the DOB (so not adding 66 on to it).
here's a fiddle
$( function doDates() {
$("#dateStart").datepicker({
minDate: '-55Y',
changeMonth: true,
changeYear: true,
maxDate: '+3M',
dateFormat: "dd/mm/yy",
onSelect: function (dateStr) {
var min = $(this).datepicker('getDate');
$("#dateEnd").datepicker('option', 'minDate', min || '0');
}
});
$("#dob").datepicker({
minDate: '-55Y',
changeMonth: true,
changeYear: true,
maxDate: '+3M',
dateFormat: "dd/mm/yy",
onSelect: function (dateStr) {
var min = $(this).datepicker('getDate');
$("#dob").datepicker('option', 'minDate', min || '0');
var startDob = $("#dob").datepicker("getDate");
var endDob = new Date();
var daysOld = (endDob - startDob) / (1000 * 60 * 60 * 24);
var retDate = startDob + 66;
$("#diffDaysOld").val(daysOld);
var yearsOld = daysOld / 365.25;
$("#age").val(yearsOld);
$("#dateEnd").val(retDate);
}
});
} );
I've tried both:
var retDate = startDob + 66;
and
var retDate = startDob + (66000 * 60 * 60 * 24);
|
|
|
|
|
I don't think you can just add numbers to a Date field. You need to get the year, add 66, and then set it to the new value. Also, 1000 * 60 * 60 * 24 is the formula for 1 day. See JavaScript Date Reference[^].
|
|
|
|
|
For
retDate = startDob + 66; //( 66000 * 60 * 60 * 24);
Substitute
var retDate = new Date(startDob.getFullYear() + 66, startDob.getMonth(), startDob.getDate());
_______________________________________________________________
Ah don't lean on me man, cause you can't afford the ticket
|
|
|
|
|
Yes, that's done the trick thank you.
Only, it would nice if I could format this date to dd/mm/yy.
I've tried:
$('#dateEnd').datepicker({dateFormat: 'dd.mm.yy'});
$('#retDate').datepicker({dateFormat: 'dd.mm.yy'});
and when this box was an actual datepicker calendar box, I could format like so:
dateFormat: "dd/mm/yy",
however, since the value is now coming from this code section:
var retDate = new Date(startDob.getFullYear() + 66, startDob.getMonth(), startDob.getDate()-1);
it results in this format:
Wed Feb 08 2073 00:00:00 GMT+0000 (GMT Standard Time)
if I could just get rid of the time, that would be good.
fiddle:
https:
modified 2-Feb-17 9:47am.
|
|
|
|
|
When submit a form with mandatory field validation with all the related tabs,Depending on Dropdown Select,Deselect Submit button should get Enable and Disable using Javascript,Ajax,Html and css.
|
|
|
|
|
What is your question?
There are two kinds of people in the world: those who can extrapolate from incomplete data.
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
Hy all there,
I have a problem. I found angular translate example on internet and tried to apply on my MVC app. And it doesnt work and I still dont get why. I tried simple app like HelloWorld and it works, but If I just add translate lib like this:
app.controller("about", ["$scope", "$translate", function ($scope, $translate)
... angular stops working
I tried the simle check test and created simple web on my desktop: index.html, app.js. And guess what? It works. So doesnt that mean that there is some problem with MVC? If it is, and dont know where.
modified 1-Feb-17 2:25am.
|
|
|
|
|
Did you setup the script to download?
<script data-require="angular-translate@*" data-semver="2.5.0" src="https://cdn.rawgit.com/angular-translate/bower-angular-translate/2.5.0/angular-translate.js"></script>
Did you inject the module into your app declaration?
angular.module("myApp",['pascalprecht.translate']);
"There are three kinds of lies: lies, damned lies and statistics."
- Benjamin Disraeli
|
|
|
|
|
Hy, yes I did setup and was injected and you know what? Yesterday it wasnt working but today it works. So doesnt it mean that there was problem with files refreshing in visual studio. Do you have any ideas about how to solve this problem, because I actualy wouldnt like to restart my pc everytime I change my file even the change is minor?
By the way, now I have another problem- now there is a problem with another angular file which belongs to diferent partial MVC page. Is there any way in angular to get logs?
So please, can you help me in these two questions now?
|
|
|
|
|
Okay, well the first is a very common problem if you're working with heavy JS front ends, and that's the browser cache. The best way to handle this (IMO) is to open your browser dev tools (normally F12), disable the browser cache, and refresh. This also has the benefit of showing the console and allowing you to inspect HTTP traffic, which is crucial in debugging JS applications.
Most browsers also support Ctl-F5, which will force a refresh from server.
Your second question is a little more free-form, since we need to define where the logs are. If they're system logs (internal to the computer that the browser is running on) then the answer is a flat no. If they're accessible from the server that your application is running on, you can just create a model for a log entry and load that model in your controller, just like you do any other sort of data.
"There are three kinds of lies: lies, damned lies and statistics."
- Benjamin Disraeli
|
|
|
|