function convertToRoman(num) {
var digits = [];
var thousand = ["I","II","III","IV"];
var number = [1,2,3,4];
var answer = [];
while (num > 0) {
digits[digits.length] = num % 10;
num = parseInt(num / 10);
}
digits.reverse();
if(digits.length === 4){
for(var i = 0; i < number.length; i++){
if(digits[i]){
answer.push(thousand[number.indexOf(digits[i])]);
}
}
}
return answer;
}
convertToRoman(3212);
danjp2016 sends brownie points to @hensn5250 :sparkles: :thumbsup: :sparkles:
:cookie: 331 | @hensn5250 |http://www.freecodecamp.org/hensn5250
function convertToRoman(num) {
var romanNum = ["MMM","MM","M","CM","DCCC","DCC","DC","D","CD","CCC","CC","C","XC","LXXX","LXX","LX","L","XL","XXX","XX","X","IX","VIII","VII","VI","V","IV","III","II","I"];
var number = [3000,2000,1000,900,800,700,600,500,400,300,200,100,90,80,70,60,50,40,30,20,10,9,8,7,6,5,4,3,2,1];
var answer = [];
for(var i = 0; i<number.length; i++){
if(num >= number[i]){
answer.push(romanNum[i]);
num = num - number[i];
}
}
return answer.join("");
}
convertToRoman(12);
justify-content: center
. I'm not sure how to proceed here.
<div v-for="(contest, index) in contests" :key="contest.id" >
<appContestSingle :contest="contest"></appContestSingle>
<hr v-if="index !== (contests.length-1) && contests.length%2 == 1">
</div>
<div class="extra" v-if="contests.length%2==1"></div>
display:none
on the :last-child
if the total number of n-childs
are an odd number.
<div :class="{'extra' : contests.length%2==1}"
codernewby sends brownie points to @darrenfj :sparkles: :thumbsup: :sparkles:
:star2: 2468 | @darrenfj |http://www.freecodecamp.org/darrenfj
https://codepen.io/Botenga/pen/QrbjZq
hey guys im stuck in trying to align these text boxes with there label. Most of the text boxes in this form are mis-aligned. Any idea why that is?
Hi! I am trying to do a css animation, but have some issues. I am trying to make an animation so that when I hover over the card, the yellow background get into place nicely and then text appear. You can see my codepen right here: https://codepen.io/danideicide/pen/Qrbjpp
Is there anyone here willing to help me? Thanks!
danideicide2_twitter sends brownie points to @marmiz :sparkles: :thumbsup: :sparkles:
:star2: 1212 | @marmiz |http://www.freecodecamp.org/marmiz
Hello guys I'm a newbie in PHP and have an assignment due in the afternoon.
Actually i have to create a store that use a session array to retrieve data input in a form, and display it . But the shopping cart has to be built with MVC.
So here is a little details of the assignement:
in the first place we have only a navbar that appears where there is two link ( both are dropdowns menu): Order and Product
When you click on ORDER the dropdown menu appears and you can read "Create" and "List" .
When you click on PRODUCT the dropdown menu appears and you can read "Create".
When you click on " Create" from the PRODUCT 's DROPDOWN you are redirect to a new page. On this new page there is a form where you can input the reference, name, price and quantity of the product you want to add and there is a save button too.
When you click on save the informations are save in a array stored in data.php. Naturally before they get stored the information input have to check if they are valid first.
When you click on " Create" from theORDER 's DROPDOWN, there is a form with two buttons that appears in the same page where you can input information about your order. And when you click on "ADD", a table appear in which you can read the order you entered . when you click on "Save", the informations are save in a array "product" stored in data.php.
When you click on " List" from the ORDER 's DROPDOWN you are redirect to a new page. On this new page there is a table where you can see the list of your order the reference, name, price and quantity of the product you want to add and there is a save button too.
And in each row there is a Details button. When you click on it an other table appears where you can see the elements ordered in that day and the Total
And i need help to know how to start this MVC model in the best way possible. All help appreciated and thanks for everything.
function findElement(arr, func) {
var num = 0;
for (var i = 0; i < arr.length; i++) {
if (func(arr[i]) === true) {
return arr[i];
}
if (i === arr.length) {
return undefined;
}
}
// return num;
}
findElement([1, 3, 5, 8, 9, 10], function(num) {
return num % 2 === 0;
});
function findElement(arr, func) {
for (var i=0; i<arr.length; i++) {
if (func(arr[i])) return arr[i];
}
}
sfshameem5 sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4786 | @masd925 |http://www.freecodecamp.org/masd925
<style type='text/sass'>
@for $j from 1 through 6 {
.text-#{$j} { font-size: 10px * $j; }
}
</style>
<p class="text-1">Hello</p>
<p class="text-2">Hello</p>
<p class="text-3">Hello</p>
<p class="text-4">Hello</p>
<p class="text-5">Hello</p>
(10 * $j)px
?
componentDidMount() {
fetch('https://thesimpsonsquoteapi.glitch.me/quotes')
.then(results => {
return results.json();
}).then(data => {
let simpsonQuotes = data.results.map((quotes) => {
return (
<div key={quotes.results}>
<p>{quotes.quote}</p>
<img src={quotes.image} />
<p>{quotes.character}</p>
<p>{quotes.characterDirection}</p>
</div>
)
})
this.setState({simpsonQuotes: simpsonQuotes});
console.log('state', this.state.simpsonQuotes);
})
}
render() {
return (
<div className="container">
<div className="container1">
{this.state.simpsonQuotes}
</div>
</div>
);
}
}
anthonygallina1 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 9215 | @sjames1958gm |http://www.freecodecamp.org/sjames1958gm
anthonygallina1 sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
data.map
and not data.results.map
@sjames1958gm
ReferenceError: simpsonQuotes is not defined
at eval
console.log('state', this.state.simpsonQuotes);
, and that was funny to say the least@anthonygallina1 alrighty then, i shall need to try that out
@sjames1958gm @anthonygallina1 special thanks to you guys for holding my hands through this haha, it is my first react project :smile:
Okay, i actually did. Here is the component
import React, { Component } from "react";
import ReactDOM from "react-dom";
export default class JsonComponent extends Component {
constructor(props) {
super(props);
this.state = {
simpsonQuotes: [],
};
}
componentDidMount() {
fetch('https://thesimpsonsquoteapi.glitch.me/quotes')
.then(results => {
return results.json();
}).then(data => {
let simpsonQuotes = data.map((quotes) => {
return (
<div key={quotes.results}>
<p>{quotes.quote}</p>
<img src={quotes.image} />
<p>{quotes.character}</p>
<p>{quotes.characterDirection}</p>
</div>
)
})
this.setState({simpsonQuotes: simpsonQuotes});
console.log('state', this.state.simpsonQuotes);
})
}
render() {
return (
<div className="container">
<div className="container1">
{this.state.simpsonQuotes}
</div>
</div>
);
}
}
// const wrapper = document.getElementById("app");
// wrapper ? ReactDOM.render(<FormContainer />, wrapper) : false;
jeffersonnnn sends brownie points to @sjames1958gm and @anthonygallina1 :sparkles: :thumbsup: :sparkles:
:star2: 9217 | @sjames1958gm |http://www.freecodecamp.org/sjames1958gm
:star2: 5875 | @anthonygallina1 |http://www.freecodecamp.org/anthonygallina1
@sjames1958gm @anthonygallina1 it worked guysss. It is on a blank canvas and i need to build out the presentation component and i need to style, but fgs, it worked!
one error though: Warning: Each child in an array or iterator should have a unique "key" prop.
function dropElements(arr, func) {
for (var i = 0; i < arr.length; i++) {
if (func(arr[i]) === false) {
arr.splice(i, 1);
}
if (func(arr[i]) === true) {
console.log(arr);
return arr;
}
}
console.log(arr);
return arr;
}
dropElements([1, 2, 3, 4], function(n) {return n > 5;})
func(arr[i])
is true. If it is, you can return a slice of arr.
function dropElements(arr, func) {
var i = 0;
while (true) {
if (func(arr[i]) === false) {
arr.splice(i, 1);
}
if (func(arr[i]) === true) {
return func(arr[i]);
}
i += 1;
if (i === arr.length) {
break;
}
}
return arr;
}
dropElements([1, 2, 3, 4], function(n) {return n > 5;})
splice()
is prob not a good method to use here since if you remove the ith element, next time it'll splice ith+2
instead of ith+1
element due to its index being changed but i
remaining the same.
function dropElements(arr, func) {
var places = [];
for (var i = 0; i < arr.length; i++) {
if (func(arr[i]) === false) {
places.push(arr[i]);
}
if (func(arr[i]) === true) {
break;
}
}
for (var i = 0; i < places.length; i++) {
if (places[i] === arr[i]) {
arr.splice(i, 1);
}
}
}
dropElements([1, 2, 3, 4], function(n) {return n > 5;})
if (places[i] === arr[i]) {
arr.splice(i, 1);
}
This will again skip over elements in arr
. Should probably look into slice()
instead of splice()
function dropElements(arr, func) {
var things = [];
for (var i = 0; i < arr.length; i++) {
if (func(arr[i]) === false) {
things.push(arr[i]);
}
if (func(arr[i]) === true) {
break;
}
}
for (var i = 0; i < things.length; i++) {
arr.shift();
}
return arr;
}
dropElements([1, 2, 3, 4], function(n) {return n >= 3;})
function dropElements(arr, func) {
for (var i=0; i<arr.length; i++) {
if (func(arr[i])) return arr.slice(i);
}
return [];
}
Hi guys, I need quick help, I am trying to valite input for UK phone number, like this
pattern="^\+?[1-9]\d{1,14}$"
but I got this error in console
Pattern attribute value ^+?[1-9]d{1,14}$ is not a valid regular expression: Uncaught SyntaxError: Invalid regular expression: /^+?[1-9]d{1,14}$/: Nothing to repeat
Does anyone know why?
\\
in your string so that it keeps the \
@sjames1958gm
instead of
pattern="^\+?[1-9]\d{1,14}$"
this
pattern="^\\+?[1-9]\\d{1,14}$"
?
@NikolaNbgd Yes, both string and regex have \
as escape character so
pattern="^\+?[1-9]\d{1,14}$"
is equivalent to the regex literal:
pattern = /^+?[1-9]d{1,14}$/
pattern = "^\\+?[1-9]\\d{1,14}$"
is equivalent to
pattern = /^\+?[1-9]\d{1,14}$/
\
get consumed as string escape character, another one as regex escape character
/^\+44/
this matches starting with +44
Regex("^\\+44")
because of what @RaphaelAddile said above about consuming \
nikolanbgd sends brownie points to @sjames1958gm :sparkles: :thumbsup: :sparkles:
:star2: 9218 | @sjames1958gm |http://www.freecodecamp.org/sjames1958gm
[1, [2], [3, [[4]]]]
and turn it into a flat array with no sub-arrays [1, 2, 3, 4]
sfshameem5 sends brownie points to @masd925 :sparkles: :thumbsup: :sparkles:
:star2: 4788 | @masd925 |http://www.freecodecamp.org/masd925
$(document).ready(function() {
users = ["ESL_SC2", "OgamingSC2"];
for (let i = 0; i < users.length; i++) {
let baseUrl = "https://wind-bow.glitch.me/twitch-api/users/";
let tailUrl = users[i];
let webLink = baseUrl + tailUrl;
$.ajax({
url: webLink,
type: "GET",
dataType: "json",
success: function(data) {
console.log(data.name);
},
error: function() {
alert("Something went wrong with the server...");
}
});
}
for (let j = 0; j < users.length; j++) {
let stream = "https://wind-bow.glitch.me/twitch-api/streams/";
let tailUrl = users[j];
let streamLink = stream + tailUrl;
$.ajax({
url: streamLink,
type: "GET",
dataType: "json",
success: function(data) {
console.log(data.stream);
},
error: function() {
alert("Something went wrong with the server...");
}
});
}
});
data
in one of them.
<button type="submit" name="btn_submit" value="btn_connexion" class="btn btn-primary">Connexion</button>
const _ = require("underscore");
const rle = ( input ) => {
console.log("input--->" + input);
//var someString ="aaa";
var someString = input;
var arr = someString.split("");
var numberCount = {};
for(var i=0; i< arr.length; i++) {
var alphabet = arr[i];
if(numberCount[alphabet]){
numberCount[alphabet] = numberCount[alphabet] + 1;
}
else{
numberCount[alphabet] = 1;
}
}
console.log("a:" + numberCount['a'], "b:" + numberCount['b']);
}
/**
* boolean doTestsPass()
* Returns true if all the tests pass. Otherwise returns false.
*/
/**
* Returns true if all tests pass; otherwise, returns false.
*/
const doTestsPass = () => {
const VALID_COMBOS = {"aaa": "a3", "aaabbc":"a3b2c1"};
let testPassed = true;
_.forEach(VALID_COMBOS, function(value, key) {
console.log(key, rle(key));
if (value !== rle(key)) {
testPassed = false;
}
});
return testPassed;
}
/**
* Main execution entry.
*/
if(doTestsPass())
{
console.log("All tests pass!");
}
else
{
console.log("There are test failures.");
}
name="btn_submit"
aita-kane sends brownie points to @gulsvi :sparkles: :thumbsup: :sparkles:
:star2: 2706 | @gulsvi |http://www.freecodecamp.org/gulsvi
console.log(key, rle(key));
inside your testing loop?
aita-kane sends brownie points to @gulsvi :sparkles: :thumbsup: :sparkles:
zhao-andy sends brownie points to @njm8 :sparkles: :thumbsup: :sparkles:
:cookie: 422 | @njm8 |http://www.freecodecamp.org/njm8
git config --global user.name ",yourname>"
git config --global user.email "<youremail>}
Could somebody check my code? I am working on Wiki viewer project and I got some problems. Once user type something in the search bar, the API supposed to bring the information but I think there is a problem related to CORS. what am I doing wrong? Thank you for you time and attention.
markclynch sends brownie points to @lydatech :sparkles: :thumbsup: :sparkles:
:star2: 2778 | @lydatech |http://www.freecodecamp.org/lydatech
origin=*
to bypass CORS
https://codepen.io/Botenga/pen/QrbjZq
hey can anyone help me? I am trying to align my inputs right next to my labels but I am having trouble doing that. Any help would be much appreciated.
console.log('https://fcc-weather-api.glitch.me/api/current?lat=' + lat + '&lon=' + lon);
===
"https://fcc-weather-api.glitch.me/api/current?lat=&lon="
expressycode sends brownie points to @njm8 :sparkles: :thumbsup: :sparkles:
:cookie: 423 | @njm8 |http://www.freecodecamp.org/njm8
expressycode sends brownie points to @njm8 :sparkles: :thumbsup: :sparkles:
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
lat = position.coords.latitude;
console.log('Lat: ' + position.coords.latitude);
lon = position.coords.longitude;
console.log('Lon: ' + position.coords.longitude);
// Do XML work here
});
expressycode sends brownie points to @njm8 :sparkles: :thumbsup: :sparkles: