|
It has been 12 days since you asked this question here. This is why we have QA sections, to ask programming questions. Please ask a question rather than posting on a discussion forum.
I am not the one who knocks. I never knock.
In fact, I hate knocking.
modified 1-May-18 8:19am.
|
|
|
|
|
Dude I am a first time user and I was not knowing how to use this forum. You don't need to react!
|
|
|
|
|
The question is just as valid here as in QA.
|
|
|
|
|
Member 13735530 wrote: Can anyone help me improving my code? Not really, since we have no idea what all that code is supposed to do. And, yes, I know you gave an outline of your program above, but it would still take quite a lot of work to fully understand it. These forums are to answer specific technical questions, not to critique people's work; basically people here do not have the time to do such things.
|
|
|
|
|
I'm new to js and I was tempted to give up. But I didn't, so as many of the quora members suggested I started to search for some good resources. I decided to choose books and coding over courses. Right now i'm reading "A smarter way to learn javascript" and I kinda like it the fact that at the end of every chapter there are 20 coding exercise.
Anyway, I found other books that catch my attention and I wonder if they are better. (Obviously i'm a beginner).
You don't know JS series (up e going)
JavaScrip for web developers
JavaScript: the definitive guide
JavaScript: the good parts
Eloquent javascript
|
|
|
|
|
After you have learned the basics of JavaScript, I highly recommend getting a nice book on JQuery, belief me this makes your life much easier.
|
|
|
|
|
If you have a computer/internet, I very highly recommend JavaScript Tutorial[^].
I learned javaScript (and php and using DOM and AJAX and HTML and CSS) from this place. For many tutorials (all free!), they have "Try It" buttons. You see the code. See the results. Can modify the results and see what it does. Better than a book. Gentle bootstrap to functional user in a short time.
Ravings en masse^ |
---|
"The difference between genius and stupidity is that genius has its limits." - Albert Einstein | "If you are searching for perfection in others, then you seek disappointment. If you are seek perfection in yourself, then you will find failure." - Balboos HaGadol Mar 2010 |
|
|
|
|
|
Hi there,
I have the following Javascript code running on a particular dynaform to update a variable with a computed total of a grid column:
var total = $('#totalVar');
var grid_details = $('#gridVar');
$("form").setOnchange( function() {
var t = grid_details.getSummary("columnVar");
total.setValue( t );
} );
I have designed some Blockchain Application Examples for mobile, but It works fine in desktop browsers but does not work on the mobile application. It fills the variable with the value '[object object]' and does not update when the grid is altered. Any ideas what is going on?
Any help appreciated!!!
Thank you.
|
|
|
|
|
Hello, I am building a JS game that consists of tiles which show a card background when you click on them, I want to make somehow that if two cards have the same image they should disappear from the deck if not they should turn to their back side again, but I am stuck on making them match. Here is my code:
The HTML:
<div class="container">
<header>
<h1> Memory Game
</h1>
</header>
<ul class="deck" id="card-deck">
<li></li>
</ul>
</div>
my Javascript:
<pre>
var masks = ["/images/1.jpg", "/images/2.jpg", "/images/3.jpg", "/images/4.jpg", "/images/12.jpg", "/images/6.jpg", "/images/1.jpg", "/images/2.jpg", "/images/3.jpg", "/images/4.jpg", "/images/12.jpg", "/images/6.jpg", ];
function shuffleMasks(masks) {
for (var i = masks.length - 1; i > 0; i--) {
var j = Math.floor(Math.random() * (i + 1));
var temp = masks[i];
masks[i] = masks[j];
masks[j] = temp;
}
}
function showModal() {
modal.style.display = "block";
$('#closeMe').hide().delay(10000).show('fast')
}
function closeModal() {
modal.style.display = "none";
}
$(document).ready(function () {
window.modal = document.getElementById('myModal');
shuffleMasks(masks);
console.log(masks)
for (var i = 0; i < masks.length; i++) {
$(".deck").append('<div class="card"> <img class="card" src="' + masks[i] + '"/></div>');
}
$(".deck").on('click', '.card', function () {
var cardVisible = $('.card img:visible').length;
if (cardVisible >= 2) $('.card img').hide();
var open = $('img').attr('id', 'open');
$(this).find("img").show()
$(".card").on('click', function () {
var source = $(this).find("img").attr('src')
alert(source);
if (source === source) {
$('.card img').hide();
}
})
})
My last function gets the src of the image and I alert so that I make sure that it get's them, but it dosen't alert once the tile has shown its front image it alerts a bunch of times, and I can't get to make my comparision right, can someone tell me what is the best way to achieve this matching and removing if the images are the same? Thanks in advance
|
|
|
|
|
I'm not sure what you're doing with the images, but I would do this:
Set an attribute on each of your .card elements perhaps called matchNum . (If you have to set this via jQuery you can use the .attr() function)
Then I would use something like this:
var otherSelectedCard = null;
$(".deck").on("click", ".card", function() {
if (otherSelectedCard === this) {
$(this).find("img").hide();
otherSelectedCard = null;
return;
}
if (otherSelectedCard !== null) {
if ($(otherSelectedCard).attr("matchNum").toString() === $(this).attr("matchNum").toString()) {
$(this).hide();
$(otherSelectedCard).hide();
otherSelectedCard = null;
}
else {
$(this).find("img").show();
var thisVar = this, otherSelectedCard2 = otherSelectedCard;
setTimeout(function() {
$(thisVar).find("img").hide();
$(otherSelectedCard2).find("img").hide();
}, 500);
otherSelectedCard = null;
}
}
else {
$(this).find("img").show();
otherSelectedCard = this;
}
});
This is my first time writing jQuery in a while so I probably goofed up somewhere in there. Hope this gives you a general idea of a solution here though
|
|
|
|
|
I'm learning Javascript.
I'm following some example code on a video.
I've got stuck trying to change some existing code.
The first step I thought would be to identify the object I'm dealing with.
What's the best way of doing this?
I've tried console.dir(document) - but that bring back *everything*.
I know I can drill down further... but I thought I'd ask here before trying anything else.
Thanks.
|
|
|
|
|
|
Richard, thanks for the reply.
I was stuck on a problem.
I couldn't see what I was doing wrong.
I had an ID and in my Javascript I had:
const CIRCLE = document.querySelector('circle');
I'd spent sooo much time trying to figure out what I had done wrong.
So... in the end I thought there must be a way to find all objects/elements on a page?
I had tried
document.querySelectorAll but wasn't sure where to type this (complete newbie... learning JS).
I found the error: I was missing a #
But... I still have my question... how could I drill down and find a specific object that I was having trouble getting the exact details of?
Hope that makes sense.
|
|
|
|
|
|
i think it's just me.
i freaked out after spending hours trying to find where i had gone wrong.
so was looking for a way to find all items on a page and then i could dig down and get the exact text i would need to put in for accessing.
thanks for all ur replies.
|
|
|
|
|
enginestar wrote: thanks for all ur replies. Happy to help. BTW, using txtspk (ur) here is frowned upon.
|
|
|
|
|
If you want to access everything in the order it is stored in as HTML, use
document.querySelector("html") to get the root html element of the document, and then use the .children array of any element to see what's inside it.
|
|
|
|
|
The req.isAuthenticated() of api.js function always returns false whether or not the user is logged in or not. Thus user is redirected to /#login at all times. I have not yet connected to MongoDB so it's just the javascript and nodejs part. I am testing my code on advanced rest client.
I tried a few solutions which suggested using cookies but it doesn't seem to work. I know there already exists a lot of answers to this question and I have tried nearly most of the answers on stack overflow but somehow nothing seems to work. I don't know what I am missing out on. I am stuck on this for a long time ao any kind of help is highly appreciated.
app.js (main file):
var http_errors = require('http-errors');
var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var passport = require('passport');
var session = require('express-session');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var api = require('./routes/api');
var authenticate = require('./routes/authenticate')(passport);
var app = express();
app.use(cookieParser('super duper secret'));
app.use(session({
secret: 'super duper secret',
resave: true,
saveUninitialized: true
}));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(express.static(path.join(__dirname, 'public')));
app.use(passport.initialize());
app.use(passport.session());
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
app.use('/api', api);
app.use('/auth', authenticate);
var initPassport = require('./passport-init');
initPassport(passport);
module.exports = app;
Routing files:-
api.js:
var express = require('express');
var router = express.Router();
router.use(function(req, res, next){
if(req.method === "GET"){
return next();
}
if (!req.isAuthenticated()){
return res.redirect('/#login');
}
return next();
});
router.route('/posts')
.get(function(req, res){
res.send({message: 'TODO return all posts'});
})
.post(function(req, res){
res.send({message: 'TODO create a new post'});
})
module.exports = router;
authenticate.js:
var express = require('express');
var router = express.Router();
module.exports = function(passport){
router.get('/success', function(req, res){
res.send({state: 'success', user: req.user ? req.user : null});
})
router.get('/failure', function(req, res){
res.send({state: 'failure', user: null, message: "Invalid username or password"});
})
router.post('/login', passport.authenticate('login', {
successRedirect: '/auth/success',
failureRedirect: '/auth/failure'
}))
router.post('/signup', passport.authenticate('signup', {
successRedirect: '/auth/success',
failureRedirect: '/auth/failure'
}))
router.get('/signout', function(req, res) {
req.logout();
res.redirect('/');
});
return router;
}
passport-init.js (file that exploits passport module):
var LocalStrategy = require('passport-local').Strategy;
var bCrypt = require('bcrypt-nodejs');
var users = {};
module.exports = function(passport){
passport.serializeUser(function(user, done) {
console.log('serializing user:',user.username)
return done(null, user.username);
})
passport.deserializeUser(function(username, done) {
User.findById(username, function(err, user){
return done(err,users[username]);
})
})
passport.use('login', new LocalStrategy({
passReqToCallback : true
},
function(req, username, password, done) {
if(!users[username]){
return done('user not found',false);
}
if(!isValidPassword (users[username],password)){
return done('invalid password', false);
}
console.log('sucessfully logged in')
return done(null, users[username]);
}
))
passport.use('signup', new LocalStrategy({
passReqToCallback : true
},
function(req, username, password, done) {
if(users[username]){
return done('username already taken', false);
}
users[username] = {
username: username,
password: createHash(password)
}
console.log('sucessfully signed in')
console.log(users[username])
return done(null, users[username]);
}
))
var isValidPassword = function(user, password){
return bCrypt.compareSync(password, user.password);
}
var createHash = function(password){
return bCrypt.hashSync(password, bCrypt.genSaltSync(10), null);
}
};
|
|
|
|
|
Hi..currently i am doing my final year project about parental monitoring and control application system using android studio.. I need to create an apps that can help parents monitor their children..an apps that can block all the website that contain adult scene, monitor and view all the activities from social media.. Do you have any suggestion about it? Thank you.I need to notify parents if the children try to search prohibited website.Then the parents can immediately block that website.
|
|
|
|
|
I am trying to figure out why this output is correct. It because var result = ""; is a string?
var result = " ";
var i = 0;
do {
i += 1;
result = result + i;
} while (i < 5);
document.write(result);
|
|
|
|
|
|
You are simply appending the numbers behind empty string repeatedly
|
|
|
|
|
Hi,
I have cshtml file in which there is jquery code, some of which is toggling in and out so that I will have better readability of the code. But some other code is not not toggling in and out. I don't know the reason, but if we can minimize the code that's not important to read at that time we can have better readability of the code.
When I searched online, it was said that Ctl+M+H would make it, yes it did make it but the problem is, when I closed the Visual Studio and opened it, all the toggles I set were lost, is there any way I can keep those toggles to my script permanently because I have to read through all the code for any change that I have to make, please I am also searching but if anybody knows it already please help me.
Any help would be very very helpful, thanks in advance.
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
-- modified 28-Mar-18 14:36pm.
|
|
|
|
|
Demo
How to increase font size of output image.
ctx.font = '90px Arial' doesn't seem to work
|
|
|
|
|
Your demo link is broken - it should be Edit fiddle - JSFiddle[^].
Several things to change:
- Change the
height attribute on the canvas tag to 90 ; - Change the textBaseline[^] to
top ; - Remove the line which sets the canvas width;
Updated demo[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|