Uncaught Error: Bootstrap's JavaScript requires jQuery. jQuery must be included before Bootstrap's JavaScript.
You need to add jquery before bootstrap js
function getLocation()
that never get called
gummygod sends brownie points to @sorinr :sparkles: :thumbsup: :sparkles:
:star2: 1386 | @sorinr |http://www.freecodecamp.org/sorinr
hemakshis sends brownie points to @khaduch :sparkles: :thumbsup: :sparkles:
:star2: 3671 | @khaduch |http://www.freecodecamp.org/khaduch
primuscovenant sends brownie points to @heroiczero :sparkles: :thumbsup: :sparkles:
:star2: 2133 | @heroiczero |http://www.freecodecamp.org/heroiczero
waleed39 sends brownie points to @joetinnyspace :sparkles: :thumbsup: :sparkles:
:cookie: 287 | @joetinnyspace |http://www.freecodecamp.org/joetinnyspace
<style>
body {
background: url(https://i.imgur.com/MJAkxbh.png
);
}
</style>
<style>
body {
background: url('https://i.imgur.com/MJAkxbh.png');
}
</style>
.html(value).fadeIn('slow')
<div id='foo'>
hey
</div>
<script>
$(document).ready(function(){
$('#foo').html('go').fadeOut();
});
</script>
transition
, you should work with visibility
rather than display
, the latter being more for element structure rather than direct visual styling
#include <bits/stdc++.h>
using namespace std;
int simpleArraySum(int n, vector <int> ar) {
// Complete this function
for(int i = 0 ; i < n ; i++)
res += ar[i];
return res;
}
int main() {
int n;
int res = 0;
cin >> n;
vector<int> ar(n);
for(int ar_i = 0; ar_i < n; ar_i++){
cin >> ar[ar_i];
}
int result = simpleArraySum(n, ar);
cout << result << endl;
return 0;
}
res=0
globally its not working can u please tell y?
external int res=0
might help
simpleArraySum
function doesn't have access to that var that is limited in scope to the main function
int res = 0;
inside simpleArraySum
function
simpleArraySum
you no longer have access to scope of main
function
but function is inside the main right?
No.
Function is called from main, but it doesn't reside in main
main
and simpleArraySum
are two entirely different functions
simpleArraySum
is defined OUTSIDE of main. Not INSIDE
#include <bits/stdc++.h>
using namespace std;
int simpleArraySum(int n, vector <int> ar) {
// Complete this function
int res = 0;
for(int i = 0 ; i < n ; i++){
res += ar[i];
}
return res;
}
int main() {
int n;
cout << "Total Number of Elements: ";
cin >> n;
vector<int> ar(n);
cout << "Please enter " << n << " numbers" << endl;
for(int ar_i = 0; ar_i < n; ar_i++){
cout << "Please enter element at index " << ar_i << " : ";
cin >> ar[ar_i];
}
int result = simpleArraySum(n, ar);
cout << "Total : " << result << endl;
return 0;
}
@sorinr
to be easy readable
Correct - to be easil
y readable
:P
@sorinr also
adding comments to the code help others
should be adding comments to the code helps
others
@SweetCodingInc its against forum policy to tell u something ..... :)
hahaha
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.2.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
var commentCount = 0;
var commentArray = [];
function Comment(cName, cComment){
var dateStamp = new Date();
console.log(dateStamp) //Console.log displays the date
commentCount++;
var cid = "comment"+ commentCount;
var upvoteCount = 0;
var downvoteCount = 0;
var replyCount = 0;
var replyArray = [];
this.cName=cName;
this.cComment=cComment;
function cReply(rName, rComment){
replyCount++;
var rid = "reply"+ replyCount;
this.rName=rName;
this.rComment=rComment;
replyArray.push(rid, rName, rComment);
}
commentArray.push(cid, cName, cComment, upvoteCount, downvoteCount, dateStamp, replyArray);
function upvote(){
upvoteCount++;
}
function downvote(){
downvoteCount++;
}
};
$('#commentForm').submit(function(event) {
event.preventDefault();
var commentAuthor = $('#newCommentAuthor').val();
var commentText = $('#newCommentText').val();
var comment = new Comment(commentAuthor, commentText);
console.log(comment.dateStamp); // Console.log displays undefined
var newCommentMarkup = '<div id="'+comment.id+'" style="background-color: #f1f1f1; padding: 5px 5px 5px 5px; margin-bottom: 5px; border-color: grey;border-style: solid;border-width: 1px; overflow: auto;"><div>'+comment.cName+' commented:</div><div>'+comment.cComment+'<br><p style="text-align:right;">'+comment.dateStamp+'<button class="upvoteBtn" style="margin-right:5px;">Upvote</button><button class="downvoteBtn">Downvote</button></p></div><hr><p class="replyArea"></p><textarea class="replyText" rows="4" cols="50" name="reply-box" placeholder="Enter your reply here"></textarea><br><button class="replyButton">Reply</button></div>';
$('#countContainer').empty().append('Total comments: '+commentCount);
$('#commentsContainer').append(newCommentMarkup);
});
});
</script>
<style type="text/css">
#newCommentContainer {
border-color: black;
border-style: solid;
border-width: 1px;
margin: 4% 24% 1% 24%;
padding: 1% 1% 1% 1%;
}
#newCommentText {
width: 100%
}
#commentsContainer {
border-color: black;border-style: solid;border-width: 1px;
margin: 0% 24% 1% 24%;
padding: 0% 1% 1% 1%;
}
#countContainer {
text-align: left;
}
#newCommentAuthor {
margin-bottom: 5px;
}
</style>
<title></title>
</head>
<body>
<div class="commentWidgetContainer">
<div id="newCommentContainer">
<form id="commentForm">
<input id="newCommentAuthor" type="text" name="name" placeholder="Name" autofocus><br>
<textarea id="newCommentText" rows="4" name="comment-box" placeholder="Enter your comment here"></textarea><br>
<input type="submit" value="Submit">
</form>
</div>
<div id="commentsContainer">
<div id="countContainer"></div>
</div>
</div>
</body>
</html>
Guys so I made and object using constructor, the dateStamp property of the object is assigned value of Date(). Why is it that the property says undefined when I try to access that property outside? i have added console.log() once after it is defined and once when is it accessed.
Please help
dateStamp
property, only a variable within the function. You set properties using the this
keyword, as you did further down the function
zlfnhmd sends brownie points to @kbaig :sparkles: :thumbsup: :sparkles:
:cookie: 508 | @kbaig |http://www.freecodecamp.org/kbaig
@zlfnhmd you haven't set a
dateStamp
property, only a variable within the function. You set properties using thethis
keyword, as you did further down the function
So that means I will have to create a date variable and pass it as constructor argument?
this
on constructor arguments
function downvote(){
this.downvote = function() {
}
.account-info {
padding: 20px 20px 0 20px;
}
.account-info label {
color: #395870;
display: block;
font-weight: bold;
margin-bottom: 20px;
}
jballin sends brownie points to @kbaig :sparkles: :thumbsup: :sparkles:
:cookie: 509 | @kbaig |http://www.freecodecamp.org/kbaig
<p <a href="http://freecatphotoapp.com"> cat photos</a> </p>
where I am going wrong with the anchor tag?
p
tag
<p <a
...
<p
vs <p>
In above codepen, why does author float both elements (left) in the account-action
class ("login" btn + "stay signed in" checkbox)
.account-action .btn {
background: linear-gradient(#49708f, #293f50);
border: 0;
color: #fff;
cursor: pointer;
font-weight: bold;
float: left;
padding: 8px 16px;
}
.account-action label {
color: #7c7c80;
font-size: 12px;
float: left;
margin: 10px 0 0 20px;
}
@VaseJS @krisb1220 you are both right, and my 'JS is only good for two things' rant was wrong. In retrospect I should probably not even have mentioned the CLI.
I was mainly trying to help @JuanMP429 (who I'm guessing is pretty new to all this based on his questions) understand how HTML and Javascript fit together, and particularly why it's worthwhile for him to keep learning HTML even though Javascript is where most of the really cool stuff happens in terms of web development.
arria2017 sends brownie points to @mot01 :sparkles: :thumbsup: :sparkles:
:cookie: 955 | @mot01 |http://www.freecodecamp.org/mot01
extends Array
does not work in Babel, which sucks. Is there a way to get the same behavior without using ES6 modules?
Array.prototype
mot01 sends brownie points to @arria2017 :sparkles: :thumbsup: :sparkles:
:cookie: 102 | @arria2017 |http://www.freecodecamp.org/arria2017
specialArray.array[2]
instead of specialArray[2]
jballin sends brownie points to @kbaig :sparkles: :thumbsup: :sparkles:
simeydk sends brownie points to @kbaig :sparkles: :thumbsup: :sparkles:
:cookie: 510 | @kbaig |http://www.freecodecamp.org/kbaig
let specialArray = new Array();
specialArray[0] = "a";
specialArray[1] = "b";
specialArray[1] // b
jballin sends brownie points to @kbaig :sparkles: :thumbsup: :sparkles:
sorinr sends brownie points to @kbaig :sparkles: :thumbsup: :sparkles:
:cookie: 511 | @kbaig |http://www.freecodecamp.org/kbaig
sorinr sends brownie points to @kbaig :sparkles: :thumbsup: :sparkles:
https://codepen.io/zlfnhmd/pen/opdGWp
So guys I have a problem again, I cant figure out why the replies dont appear unless the comment to be replied has a comment under it. That is if there are n comments I can only reply to n-1 comments.
Please help me out.
I must say I have learnt a great deal since i started this project
``
var randomNumber = Math.floor(Math.random() * 100) + 1;
var guesses = document.querySelector('.guesses');
var lastResult = document.querySelector('.lastResult');
var lowOrHi = document.querySelector('.lowOrHi');
var guessSubmit = document.querySelector('.guessSubmit');
var guessSubmit = document.querySelector('.guessField');
var guessCount = 1;
var resetButton;
function checkGuess(){
var userGuess = Number(guessField.value);
if(guessCount = 1){
guesses.textContent = "Previous guesses";
}
guesses.textContent += userGuess + " ";
if(userGuess === randomNumber)
{
lastResult.textContent = "Congratulations! You got it right!";
lastResult.style.backgroundColor = "gray";
lastResult.style.color = "limegreen";
lowOrHi.textContent = " ";
setGameOver();
}
else if(guessCount === 10)
{
lastResult.textContent = "THE GAME IS OVER!";
setGameOver();
}
else{
lastResult.textContent = "Wrong Guess!";
lastResult.style.backgroundColor = "red";
lastResult.color = "white";
if(userGuess < randomNumber)
{
lowOrHi.textContent = "The last guess was too low!";
}
else if (userGuess > randomNumber)
{
lowOrHi.textContent = "The last guess was too high";
}
}
guessCount++;
guessField.value = "";
guessField.focus();
}
guessSubmit.addEventListener('click', checkGuess);
``
``<h1>Number Guessing Game</h1>
<p>We have selected a randome number between 1 and 100.See if you can guess the number in 10 turns or less</p>
<br>
<p>We will tell you if your guess is too high or too low</p>
<div class="form">
<label for="guessField">Enter a guess:</label><br>
<input type="text" id="guessField" class="guessField">
<input type="submit" class="guessSubmit" value="Submit Guess">
</div>
<div class="resultParas">
<p class="guesses"> </p>
<p class="lastResult"></p>
<p class="lowOrHi"></p>
</div>``
``
<h1>Number Guessing Game</h1>
<p>We have selected a randome number between 1 and 100.See if you can guess the number in 10 turns or less</p>
<br>
<p>We will tell you if your guess is too high or too low</p>
<div class="form">
<label for="guessField">Enter a guess:</label><br>
<input type="text" id="guessField" class="guessField">
<input type="submit" class="guessSubmit" value="Submit Guess">
</div>
<div class="resultParas">
<p class="guesses"> </p>
<p class="lastResult"></p>
<p class="lowOrHi"></p>
</div>
``
<h1>Number Guessing Game</h1>
<p>We have selected a randome number between 1 and 100.See if you can guess the number in 10 turns or less</p>
<br>
<p>We will tell you if your guess is too high or too low</p>
<div class="form">
<label for="guessField">Enter a guess:</label><br>
<input type="text" id="guessField" class="guessField">
<input type="submit" class="guessSubmit" value="Submit Guess">
</div>
<div class="resultParas">
<p class="guesses"> </p>
<p class="lastResult"></p>
<p class="lowOrHi"></p>
</div>
var randomNumber = Math.floor(Math.random() * 100) + 1;
var guesses = document.querySelector('.guesses');
var lastResult = document.querySelector('.lastResult');
var lowOrHi = document.querySelector('.lowOrHi');
var guessSubmit = document.querySelector('.guessSubmit');
var guessSubmit = document.querySelector('.guessField');
var guessCount = 1;
var resetButton;
function checkGuess(){
var userGuess = Number(guessField.value);
if(guessCount = 1){
guesses.textContent = "Previous guesses";
}
guesses.textContent += userGuess + " ";
if(userGuess === randomNumber)
{
lastResult.textContent = "Congratulations! You got it right!";
lastResult.style.backgroundColor = "gray";
lastResult.style.color = "limegreen";
lowOrHi.textContent = " ";
setGameOver();
}
else if(guessCount === 10)
{
lastResult.textContent = "THE GAME IS OVER!";
setGameOver();
}
else{
lastResult.textContent = "Wrong Guess!";
lastResult.style.backgroundColor = "red";
lastResult.color = "white";
if(userGuess < randomNumber)
{
lowOrHi.textContent = "The last guess was too low!";
}
else if (userGuess > randomNumber)
{
lowOrHi.textContent = "The last guess was too high";
}
}
guessCount++;
guessField.value = "";
guessField.focus();
}
guessSubmit.addEventListener('click', checkGuess);
function checkGuess(){
function SpecialArray(array) {
this.arr = array;
}
SpecialArray.prototype.printAllValuesObjs = function() {
this.arr.forEach(function(obj) {
for (key in obj) {
console.log(obj[key]);
}
})
}
var special = new SpecialArray([{a:1, b:2}, {c:3, d:4}]);
special.printAllValuesObjs()
// 1
// 2
// 3
// 4
class SetofElements extends Array {
hasValues() {
return this.filter(element => element.value)
}
}
set[i] = foo
and set.push(foo)
and all the other array goodness, but with the ability to add my own custom methods which describe my "business logic"
@Kingwindie Its running because of this
var guessSubmit = document.querySelector('.guessSubmit');
var guessSubmit = document.querySelector('.guessField');
so the .guessField
is overwriting and therefore running when clicked.
My current scenario is this:
I am writing a sudoku solver. As part of this, I have the idea of a row/column/block, which primarily consists of 9 cells, so an array is a good fit. I then want a function that says "find all the numbers which haven't been entered in this row, and for each of them find all the cells that can possibly be that value".
I can do this in an external function, but the niftiest implementation, in my opinion is the extends Array
with methods
kingwindie sends brownie points to @ezioda004 :sparkles: :thumbsup: :sparkles:
:cookie: 373 | @ezioda004 |http://www.freecodecamp.org/ezioda004
class extends
, unless you extend a 'buitin' such as Array
Array
which does doesn't have the extra methods and properties of the custom class
;
. I get Java PTSD.
@simeydk If you do
const e = new Extender()
console.log(e)
in the console
Extender []
length: 0__
proto__: Array
Which seems to imply that Extender is derived from Array
kbaig sends brownie points to @jballin :sparkles: :thumbsup: :sparkles:
:cookie: 25 | @jballin |http://www.freecodecamp.org/jballin
extends Array
, so I can't have both at the same time
extends array
https://stackoverflow.com/questions/33832646/extending-built-in-natives-in-es6-with-babel
import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, Validators, FormControl } from '@angular/forms';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
title = 'app';
numberFormat = '';
ngOnInit(): void {
console.log(formatedNumber(12121212));
formatedNumber(this.numberFormat);
}
}
function convertNumber(num){
return new Intl.NumberFormat().format(Math.round(num*10)/10);
}
function formatedNumber(num){
if(num >= 1000000)
return convertNumber(num/1000000)+'M';
if(num >= 1000)
return convertNumber(num/1000)+'k';
return convertNumber(num);
}
<div class="wrapper">
<input type="number" name="name" id="name" [ngModel]="numberFormat" #number />
<label for="name" (click)="ngOnInit(number.value)">prettify</label>
</div>
;
is just better. Thanks for sharing
ezioda004 sends brownie points to @jballin :sparkles: :thumbsup: :sparkles:
:cookie: 26 | @jballin |http://www.freecodecamp.org/jballin
jballin sends brownie points to @ezioda004 and @kbaig :sparkles: :thumbsup: :sparkles:
:cookie: 515 | @kbaig |http://www.freecodecamp.org/kbaig
:cookie: 374 | @ezioda004 |http://www.freecodecamp.org/ezioda004
breedHorse += "<button id='aHorse' class='btn-default btn-sm'>A</button>";
breedHorse += "<button class='btn-default btn-sm' id='cHorse'>C</button>";
breedHorse += "<button class='btn-default btn-sm' id='fHorse'>F</button>";
breedHorse += "<button class='btn-default btn-sm' id='gHorse'>G</button>";
breedHorse += "<button class='btn-default btn-sm' id='mHorse'>M</button>";
breedHorse += "<button class='btn-default btn-sm' id='pHorse'>P</button>";
breedHorse += "<button class='btn-default btn-sm' id='qHorse'>Q</button>";
breedHorse += "<button class='btn-default btn-sm' id='sHorse'>S</button>";
breedHorse += "<button class='btn-default btn-sm' id='tHorse'>T</button>";
/*
for(var i=0; i < fHorses.length; i++){
for(var j=0; j < bHorse.length; j++){
breedHorse += "<ul class = 'btn-toolbar oneToolbar list-unstyled'>";
breedHorse += "<li><button class = 'btn-default btn-sm' id = ''><a href='" + fHorses[j] +"'>" + bHorse[i] + "</a></button>";
}
}
breedHorse += "</ul>";
*/
document.getElementById("Horses").innerHTML = breedHorse;
}
else if(H =="type" || H == "Type" || H == "types" || H == "Types"){
for(var k=0; k < tHorse.length; k++){
typeHorse += "<ul class = 'btn-toolbar oneToolbar list-unstyled'>";
typeHorse += "<li><button class = 'btn-default btn-sm' id = ''>" + tHorse[k] + "</button>";
}
typeHorse += "</ul>";
document.getElementById("Horses").innerHTML = typeHorse;
}
});
https://codepen.io/zlfnhmd/pen/opdGWp
So guys I finally completed my project. Big thanks to @kbaig @cmccormack @sjames1958gm
zlfnhmd sends brownie points to @kbaig and @cmccormack and @sjames1958gm :sparkles: :thumbsup: :sparkles:
json
which will be an object containing the returned data $("#weather-container").text(JSON.stringify(json));
davidbelmares sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 8847 | @sjames1958gm |http://www.freecodecamp.org/sjames1958gm