GraphLog Posted August 13, 2012 Report Posted August 13, 2012 Salutari, m-am hotarat si eu sa invat JavaScript si am citit niste chestii pe net.Se da urmatoarea problema :Printing your own name ten times.Eu, stiu sa fac cu numere, de exemplu:var counter="1";for (counter = 1; counter <= 10; counter = counter + 1) { console.log(counter);}Dar, daca incerc cu un string, cum e "Alecs":var counter="Alecs";for (counter = "Alecs"; counter <= "Alecs" * 10; counter = counter + 1) { console.log(counter);}Imi returneaza:AlecsCum as putea face sa imi arate numele de 10 ori?Multumesc anticipat . Quote
Sim Master Posted August 13, 2012 Report Posted August 13, 2012 for (var counter = 0; counter<10; counter++){ console.log("Alecs");}Loopul e mai degraba ce actiune sa o repete de cate ori ai pus tu. Quote
adriann54 Posted August 13, 2012 Report Posted August 13, 2012 Vrei sa iti arate numele de 10 ori?Desi nu am lucrat mult cu JS sper ca este corect.var counter=1;for (counter = 1; counter <= 10; counter = counter + 1) { console.log("Alecs");}sauvar counter=1;var nume="Alecs";for (counter = 1; counter <= 10; counter = counter + 1) { console.log(nume);}Variabila counter trebuie sa fie un numar care ajunge de la 1 la 10 astfel incat de fiecare data cand creste sa se intample ceva adica sa iti scrie numele tau. Quote
GraphLog Posted August 13, 2012 Author Report Posted August 13, 2012 Mie la inceput , in lectie, mi-au dat codul cu var counter="1";Aia la ce ajuta, sau de ce nu ne foloseste?Mersi mult.EDIT: Si de ce counter++ si nu counter = counter+1 ? Quote
Sim Master Posted August 13, 2012 Report Posted August 13, 2012 Fie ca treci var counter = 1; la inceput sau direct cand declari loop-ul e tot aia.EDIT: Daca il declari inainte sa incepi loopul atunci mai poti folosi variabila si mai departe in cod. Quote
adriann54 Posted August 13, 2012 Report Posted August 13, 2012 Pentru ca OOP.counter++ e la fel ca si counter = counter + 1 e la fel ca si counter += 1 Quote
adriann54 Posted August 13, 2012 Report Posted August 13, 2012 Daca stii engleza mai bine cauti o carte pe Amazon (Amazon | Query : javascript) despre JavaScript si inveti acolo. Asa este cel mai recomandat. Daca are review-uri bune cauta-i ebook-ul pe net.Daca nu stii engleza ori incerci sa cauti una in romana, ori te duci la magazin sa-ti cumperi. Quote
totti93 Posted August 13, 2012 Report Posted August 13, 2012 i++ == i = i + 1 == i += 1 == ++iAtentie, exista diferente intre i++ si ++i (post-incrementare, pre-incrementare). Exemplu:Pre-incrementare;var i = 0;var pre = ++i;alert(pre); // 1alert(i); // 1Post-incrementare;var i = 0;var post = i++;alert(post); // 0alert(i); // 1 Quote
GraphLog Posted August 13, 2012 Author Report Posted August 13, 2012 @totti93 Daca tot esti pus pe ajutat, mai am o problema Deci, cerintele sunt:Write a for loop that prints out numbers 100 through 150. The test will fail, but you can check the console to make sure you did it right.Now, inside the block, change your code so you are calculating the square of i and store it in the variable square. Use multiplication to calculate the square, not the ^ character.Change the console.log statement so it outputs the square instead of i.Save the world.Eu am facut codul asta:var square=(Math.sqrt(i));for (var i=100; i<=150; i++) { console.log(square);}Dar imi arata:Oops, try again. Make sure you're 1) starting the loop on 100 and 2) squaring it.Ai vreo idee?Multumesc mult pt indrumari Quote
Sim Master Posted August 13, 2012 Report Posted August 13, 2012 Nu ai cum sa calculezi patratul unui numar pe care il declari mai tarziu. Si Math.sqrt() calculeaza radacina patrata, adica scoate de sub radical, iar acolo zice sa calculezi patratul, adica la puterea a doua si asta folosind inmultirea.for (i = 100; i<=150; i++){ var square = i*i; console.log(square);} Quote
GraphLog Posted August 14, 2012 Author Report Posted August 14, 2012 Daca nu va enervez prea tare, am mai gasit o problema .Cerintele sunt:Define the calculateTotalCosts function with three parameters - salary, numWorkers, city.Declare fixedCosts and assign it a value of 5000. Declare variableCosts and assign it the value of salary * numWorkers.If the startup is in NYC, the rent is 30000.If the startup is in "BEJ" (Beijing), the rent is 25000.If the startup is based anywhere else, the rent is 10000.Use the function to calculate the costs for a startup with salaries of 40000, 3 workers, and based in any city other than "NYC" or "BEJ". This means taking in those numbers as parameters for the calculation, and using an if statement to check which city it is in.Acuma, am scris eu ceva ceva, dar imi da "Oops!Try again."Codul meu e:var TotalCosts = function(salary, numWorkers, city) { var fixedCosts = 5000; var variableCosts = salary * numWorkers; if (city === "NYC") { return fixedCosts + variableCosts + 30000; } else if (city === "BEJ") { return fixedCosts + variableCosts + 25000; } else { return fixedCosts + variableCosts + 10000; }};TotalCosts(40000,3,"BUC");Multumesc ^^. Quote
DarkyAngel Posted August 14, 2012 Report Posted August 14, 2012 Salutari, m-am hotarat si eu sa invat JavaScript si am citit niste chestii pe net.cine înva?? javascript aici, ?i ar trebui s? rezolve problemele pe baza a ce a înv??at, noi sau tu? btw:Define the calculateTotalCoststu ai f?cut:var TotalCosts = function(salary, numWorkers, city) { Quote
GraphLog Posted August 14, 2012 Author Report Posted August 14, 2012 Da, aia era problema..Mersi mult.Pai,eu incerc sa le rezolv, dar tinand cont ca e sectiune de webdesign ce tine si de asta, mai pun niste intrebari.Nu te obliga nimeni sa-mi citesti threadul sau sa raspunzi, din cate vezi nu am cerut scripturile de la 0, sau "da-mi si mie un script sa fac asa asa", ci doar niste completari / indrumari. Quote
AlStar Posted August 14, 2012 Report Posted August 14, 2012 (edited) Ai inceput cu stangul. Nu poti invata JS cand nu ai o formata o baza in programare in general.Din ce vad, tu arunci "cuvinte" prin source-code fara sa ai idee cum functioneaza. Pai avand in vedere ce-ai scris in primu' post, (counter='Alecs'; counter<=..etc..) nu are rost sa treci mai departe pana nu intelegi cum merge treaba.Tu postezi acilea ca nu intelegi, astia iti da mura-n gura ca n-au chef sa explice...ce castigi? Edited August 15, 2012 by AlStar Quote
GraphLog Posted August 17, 2012 Author Report Posted August 17, 2012 @AlStar Pai nu e prea bine explicat tutorialul..Imi poti recomanda o carte?De stiut stiu HTML + CSS. Quote
Sim Master Posted August 17, 2012 Report Posted August 17, 2012 Iti recomand cursurile video de la lynda.com. Le gasesti pe torrente. Quote