Get help on our basic JavaScript and Algorithms Challenges. If you are posting code that is large use Gist - https://gist.github.com/ paste the link here.
hi guys, first and foremost: thank you for the community feel of this place. Whenever, i come back, it never feels like. So here is m problem: i am trying to implement a carousel effect on a web page, i think(?) i am getting the code right, but the effect isn't just happening. Here is my script.js
code
var slideInterval = 3500;
function getFigures() {
return document.getElementById('carousel').getElementsByTagName('figure');
}
function moveForward() {
var pointer;
var figures = getFigures();
for (var i = 0; i < figures.length; i++) {
if (figures[i].className == 'visible') {
figures[i].className = '';
pointer = i;
}
}
if (++pointer == figures.length) {
pointer = 0;
}
figures[pointer].className = 'visible';
setTimeout(moveForward, slideInterval);
function startPlayback() {
setTimeout(moveForward, slideInterval);
}
startPlayback();
Please somebody, anybody, give me a clue as to where error is.
}
It works! It works! It works! cue maniacal laughter
Thanks @sjames1958gm , you rock.
jeffersonnnn sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
$(document).ready(function(){
var usernam = $('#username').val();
var passwor = $('#password').val();
$("#register").click(function(){
$.ajax({
type : 'post',
url : 'http://localhost:8000/login',
data : {
username : usernam,
password : passwor
},
ContentType : "application/json",
dataType : "json",
success : function(data,err){
console.log(data);
if(err)
console.log(err);
}
});
});
});
ContentType
rather than contentType
type
should be method
type
is ok
url: '/login'
wanna
or say want to
.. wanna to
is bad and redundant ;)
@1532j0004kg the reason the data is not posted is that you're doing
var usernam = $('#username').val();
var passwor = $('#password').val();
on document ready. You want to do that when you click the button
$("#register").click(function(){
var usernam = $('#username').val();
var passwor = $('#password').val();
$.ajax({
type : 'post',
url : 'http://localhost:8000/login',
data : {
username : usernam,
password : passwor
},
ContentType : "application/json",
dataType : "json",
success : function(data,err){
console.log(data);
if(err)
console.log(err);
}
});
});
$(document).ready(function() {
var usernam = $('#username');
var passwor = $('#password');
$('#register').click(function() {
$.ajax({
type: 'post',
url: 'http://localhost:8000/login',
data: {
username: usernam.val().trim(),
password: passwor.val().trim(),
},
ContentType: 'application/json',
dataType: 'json',
success: function(data, err) {
console.log(data);
if (err) console.log(err);
},
});
});
});
method: 'post'
not type:'post'
var express = require("express");
var router = express.Router();
var mongoose = require('mongoose');
var usersSchema = mongoose.Schema({
username : String,
password : String
});
var usersModel = mongoose.model('users' , usersSchema);
router.post('/login' ,function(req,res){
var newUser = new usersModel();
newUser.username = req.body.username;
newUser.password = req.body.password;
newUser.save(function(err,savedObject){
if(err)
{
res.statusCode(500).send();
}
else {
res.send(savedObject);
}
});
});
module.exports = router;
@1532j0004kg I already told you
You want to do that when you click the button
.val
)
application/json
, jQuery will convert data from the server to js object.
type : json
post
data
object to JSON
dataType: 'json'
.ExecuteNonQuery
which returns the number of row's affected.. well its meant to be used only with DML statements.. hence why it wasn't working for me with a Select statement :neutral_face:
$(document).ready(function(){
$("#register").click(function(){
$.ajax({
type : "post",
url : 'http://localhost:8000/login',
data : JSON.stringify({
username : $('#username').val(),
password : $('#password').val()
}),
contentType : "application/json",
dataType : 'json',
success : function(data,err){
console.log(data);
if(err)
console.log(err);
}
});
});
});
$.ajax({
type: 'post',
url: 'http://localhost:8000/login',
data: {
username: $username.val().trim(),
password: $password.val().trim(),
},
ContentType: 'application/json',
success: function (data, err) {
console.log(data);
if (err) console.log(err);
},
});
Also, instead of doing
console.log(data);
if (err) console.log(err);
you can simply do
console.log(err ? err : data);
sorry 1532j0004kg, you can't send brownie points to yourself! :sparkles: :sparkles:
1532j0004kg sends brownie points to @sweetcodinginc :sparkles: :thumbsup: :sparkles:
:cookie: 198 | @sweetcodinginc |http://www.freecodecamp.org/sweetcodinginc
Hey, I am just working on the https://www.freecodecamp.org/challenges/exact-change challenge.
I just read through the hints, FCC gives me, but I can't understand what they mean with this one:
"Life is easier when you get to know the value of each currency type in the register instead of how much money is composed of that particular currency. So be sure to watch out for that."
I honestly don't quite know what this sentence means, as I already seem to know, what values are linked to each currency...?
[["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.10], ["QUARTER", 4.25], ["ONE", 90.00], ["FIVE", 55.00], ["TEN", 20.00], ["TWENTY", 60.00], ["ONE HUNDRED", 100.00]]
HELP
/*function destroyer(arr) {
return arguments[0].filter(notThose(val){
return val !== arguments[1] && val !== arguments[2];
});
}
// USE FILTER TO TAKE OUT ARGUMENT[1.]
destroyer([1, 2, 3, 1, 2, 3], 2, 3); */
SAYS MY SYNTAX IS OFF
var args = Array.prototype.slice.call(arguments,1);
and then solve it using arr
and args
.