#1 of 25 Beginner Projects - HTML, CSS, & JavaScript - Colors ( Responsive Design )

Поделиться
HTML-код
  • Опубликовано: 1 окт 2024
  • In this project we create a project that changes the background color with the click of a button. We also teach you how to use bootstrap to make the process of designing buttons faster and we teach you how to do it manually with CSS.
    Try it before you build it ( Hosted with GitHub Pages):
    miguelznunez.g...
    GitHub Repository ( Don't forget to star !):
    github.com/mig...
    Sponsor me on GitHub!
    github.com/spo...
    Follow my blog:
    / miguelznunez
    Email : mignunez@csumb.edu
    Medium : / miguelznunez
    Codepen : codepen.io/mig...
    GitHub : github.com/mig...

Комментарии • 99

  • @Epikht
    @Epikht 2 года назад +21

    I know some Js but it was kinda hard for me to turn them into project and the fact that you explain everything from the very beginning deserve a follow ❤ Thank you

  • @soundarTech
    @soundarTech Год назад +13

    Actually your video is too good , but in my opinion ,
    function changeColors(){
    const r = Math.floor(Math.random()*255);
    const g = Math.floor(Math.random()*255);
    const b = Math.floor(Math.random()*255);
    body.style.background = `rgb(${r},${g},${b})`;
    It will create an random Colors between 0 to 255 colors
    I hope this will helpful.❤ If you love this , pin me ♥️♥️

    • @kazi5432
      @kazi5432 Год назад

      it should be * 256

    • @caretib4283
      @caretib4283 Год назад

      function change() {
      const r = Math.floor(Math.random() * 255);
      const g = Math.floor(Math.random() * 255);
      const b = Math.floor(Math.random() * 255);
      document.querySelector("body").style.background = `rgb(${r},${g},${b})`;
      }

  • @rouilliew
    @rouilliew 9 месяцев назад +5

    My first JS Project! I barely had any JS exposure, and it started looking more like Greek and less comprehensive. That's when I knew I had to build something to make sense of everything. Thanks a ton! This helped a lot in making concepts stick. I intend to do all 25. 🎉

  • @elg281
    @elg281 Год назад +2

    So ... Instead of using 0 in your function you could use 1 and the first color to run would be blue. Correct? I'll try it out.

  • @lenenousi4965
    @lenenousi4965 3 года назад +6

    Thanks. Now I understood use for bootstrap. Practice is much better for learning. I loved it!

  • @abuaqeel292
    @abuaqeel292 Год назад +1

    function changColor() {
    var color = ["red", "green", "black", "yellow"]
    document.querySelector(".container").style.background = color[Math.floor(Math.random() * color.length)]
    }

    • @seenup9056
      @seenup9056 Год назад

      can you explain me why width not fully covered please.

  • @chumbuzzy4694
    @chumbuzzy4694 Год назад +1

    Сan you help please. I want the color that is currently on the background to be displayed, I can do this with if, else conditions. But I'm sure there is a better way, I now just output the entire array.
    const button = document.querySelector('.change__color');
    const colorTxt = document.getElementsByClassName('color')[0];
    let index = 0;
    button.addEventListener('click', function(event) {
    let colors = ["red", "blue", "pink", "black", "orange", "green", "white"];
    const body = document.body;
    body.style.backgroundColor = colors[index++];
    if(index > colors.length -1) {
    index = 0;
    };
    if(body.style.backgroundColor == 'black') {

    colorTxt.style.color = '#fff';
    } else {
    colorTxt.style.color = '#333';
    };
    colorTxt.innerHTML = `Цвет меняется`;
    });

  • @sahinduezguen
    @sahinduezguen 6 месяцев назад

    Nice little tutorial. Thx!
    Just curious: how would the JS-script look like if i'd want to change to color of the container AND the body but with different values? Like, the container in yellow but the body in red.

  • @anmolrai1438
    @anmolrai1438 Год назад +4

    you're the one i was searching for to start a project as a beginner🙏🙏🙏🙏

  • @BrownStore
    @BrownStore Год назад +1

    I am so lost. when I try and type style.background = colors[index++]; it does nothing on my end. I'm not sure what I'm doing wrong

    • @MariosGeorgiosKatis
      @MariosGeorgiosKatis 21 день назад

      its document.getElementsByTagName("body")[0].style.background = colors[index++]; all together !!!! i just found out

  • @farhadcohan3245
    @farhadcohan3245 2 года назад +1

    Anyone does not understands how html CSS JS have to watch your videos then they all will arrived to AHA moment thanks again could do a video about JS syntax's like how do you know to use them I followed step by steps your to do list (groceries video) but I'm getting error on pencil code I checked everything like spelling quatations to

  • @farhadcohan3245
    @farhadcohan3245 2 года назад +3

    I have watched many videos so far you are the best bcz you explain everything in very simple way🤙🙏

  • @HHJoshHH
    @HHJoshHH Год назад

    Never-mind I figured out I screwed up the index = 0 by saying index = o. 🤦🏻‍♂️

  • @23mohdmujeeb
    @23mohdmujeeb 8 месяцев назад

    This is code from your actual sheet source code:
    var colors = ["Orangered","Blue","Yellow","Green","Orange", "Cyan","DodgerBlue", "Violet", "Navy", "Purple", "YellowGreen", "OrangeRed", "SlateBlue", "Salmon", "Crimson", "HotPink", "Magenta"];
    var index = 0;
    document.querySelector("#submit").addEventListener("click", () => {
    if(index > colors.length - 1)
    index = 0;
    document.body.style.backgroundColor = colors[index++];
    });

  • @23mohdmujeeb
    @23mohdmujeeb 8 месяцев назад

    Thanks, but this good did not work for me, may be i am doing some mistake, but it check your link and source, your JS code is entirely different then video, when copy paste your actual code, its working

  • @yvng4697
    @yvng4697 Год назад +2

    this is kinda weird i wrote everything as u wrote but js doesnt work

    • @codefoxx
      @codefoxx  Год назад +2

      Did you link the js file in the html?

    • @yvng4697
      @yvng4697 Год назад

      @@codefoxx am gonna do this project again, next time i will use bootstrap and everything coz i didnt use it

  • @clydeforland5944
    @clydeforland5944 Год назад +1

    Just stumbled arcoss this and my mind is blown! Aspiring Front End & UX Designer here. Thanks for this!!

  • @Dope_Stories
    @Dope_Stories Год назад

    IDK if I am crazy or what but this does not work it is also missing {} on the if statement but that did not fix it ffor me either

  • @sudarshanahire
    @sudarshanahire 3 года назад +2

    Learn in a different style of code thanks

  • @arthabhunter
    @arthabhunter Год назад +1

    thankyou very much . the way you revise the what this things do appreciate bro.

  • @lachiemiles5737
    @lachiemiles5737 2 месяца назад

    the colour only changes once when I run. Changes to red, then nothing else?

  • @AdewunmiOluwole
    @AdewunmiOluwole 5 месяцев назад

    Not straight forward, i don't get it...😥

  • @MODY-qz3lw
    @MODY-qz3lw Месяц назад

    It worked , thanks ❤

  • @ps2530
    @ps2530 Год назад +2

    It doesn't really work at my side I did everything but when I click it doesn't change the colors😶

    • @crispycrust5103
      @crispycrust5103 9 месяцев назад +1

      same here. tried 3 different times from scratch. everything is word for word and it doesnt work.

    • @crispycrust5103
      @crispycrust5103 9 месяцев назад +1

      very confused. i had it all setup properly. change the link from src="file name" to href="file name" then swapped back to src again and now it links properly. gotta love it.

    • @aikadxuk7303
      @aikadxuk7303 9 месяцев назад

      ​@@crispycrust5103Nope, just write

  • @Joe-qp9ix
    @Joe-qp9ix 2 месяца назад

    I know these videos are older but if you do ever end up making more, I would recommend giving some more explanations. I just went along with what you said through the first half of the video without any idea as to why or what I was doing, and you were all over the place. IDE, browser, IDE, browser..

  • @dr.kamrunnahar2209
    @dr.kamrunnahar2209 Год назад +1

    Thank you so much, I've been learning js but I had no idea how to use it in codes. This video really helped a lot...

  • @martynaspuotkalis4117
    @martynaspuotkalis4117 Год назад

    Good example but not enough explanations. Otherwise, thanks for sharing.

  • @mohdsameer7433
    @mohdsameer7433 Год назад

    Hello sir , Awesome i'm a beignner this is good i only don't understand why your are creat a index variable i tryed with out that index variable it's doesn't work can you tell me?

  • @1littlehelper
    @1littlehelper Год назад +1

    very good example of 'practice makes perfect'. Thank you for the videos - learnt a lot!

  • @moaad95
    @moaad95 Год назад

    Thanks for video, i enjoyed it.
    i have a suggestion for the index update:
    index = index % colors.length;
    This means no need for the if statement.

  • @kazianzuman6401
    @kazianzuman6401 3 года назад +1

    i was following this video , but my JS didn't work. my button didn't change colors . Can u fix this !!

    • @kazianzuman6401
      @kazianzuman6401 3 года назад +1

      var index = 0;
      function changeColors()
      {var colors = ["red","blue","yellow","green","purple"];

      document.getElementsByTagName("body")[0].
      style.background = colors[index++];
      if (index > colors.length -1)
      index = 0;
      }

    • @kazianzuman6401
      @kazianzuman6401 3 года назад

      just figured , my js file was not linked properly :D . it was an awesome video . Merci Beaucoup!!

  • @thepratikshow2666
    @thepratikshow2666 Год назад +1

    amazing learned a lot today

  • @alialpert.8144
    @alialpert.8144 9 месяцев назад

    Simple and very effective video, I !m really grateful for the effort. thanks a lot🙏

  • @DwightTam
    @DwightTam Год назад +1

    11:09 missing some {

  • @t3true-games
    @t3true-games Год назад +1

    cool thx

  • @delanlee2897
    @delanlee2897 2 года назад +1

    Thank you SO much this video is awesome!

  • @oluwatosingbolabo9201
    @oluwatosingbolabo9201 Год назад +1

    thank you so much for serving us a self explanatory tutorial, this is simplicity in its simplest form

  • @stmike3003
    @stmike3003 2 года назад +1

    Thank you very much!

  • @AdewunmiOluwole
    @AdewunmiOluwole 5 месяцев назад

    Not clear

  • @chantelm7304
    @chantelm7304 2 года назад +1

    Thanks, awesome video!

  • @raohadeed9268
    @raohadeed9268 Год назад

    If we don't use index=0 in js
    What will happen😊.

  • @fadzaiemmahnembaware
    @fadzaiemmahnembaware 8 месяцев назад

    Well explained, I understood this video as a beginer.

  • @faisalamin001
    @faisalamin001 3 года назад +1

    Thank you!!!!

  • @subie2033
    @subie2033 2 года назад +1

    Great video! You've actually made me feel like I was programing something!!

  • @MhamedVdel
    @MhamedVdel Год назад

    i didn't understand -1 after length
    somone to me please

  • @braindead2813
    @braindead2813 10 месяцев назад

    wow! this is 10x slower than python I am shook!

  • @rosen.espinoza9477
    @rosen.espinoza9477 3 года назад +1

    Thank you for this!

  • @saifadnan864
    @saifadnan864 9 месяцев назад

    good visual explanation as it's needed for learners

  • @ps2530
    @ps2530 Год назад

    but still very good video thanks 🤩

  • @akashnimgade1631
    @akashnimgade1631 Год назад

    thank you for this project bro...

  • @thatsawesome.
    @thatsawesome. Год назад

    Thank you so much :)))

  • @icbinroshen4618
    @icbinroshen4618 Год назад

    Thanks for the video

  • @farhadcohan3245
    @farhadcohan3245 2 года назад

    Yes your video on to list groceries

  • @powderberrykun
    @powderberrykun Год назад

    Before I start my real projects, I use this one as kind of a warm up.

  • @teclyt_solutions3839
    @teclyt_solutions3839 Год назад

    Thanks for this tutorial

  • @khushisaraswat5826
    @khushisaraswat5826 Год назад

    Thank u so much bro

  • @aka...7943
    @aka...7943 Год назад

    شكرا لك من اعماق قلبي على هذا الشرح المفهوم و المختصر في نفس الوقت 🤍

  • @danylipsker
    @danylipsker 3 года назад

    Thanks to you I start to understand web design
    Thanks

  • @sdvasd
    @sdvasd Год назад

    thank you

  • @mohammedyunus3968
    @mohammedyunus3968 Год назад

    can't we do it without bootstrap just with CSS??

  • @afsanarousne8941
    @afsanarousne8941 Год назад

    thnx bro

  • @jimcari7255
    @jimcari7255 Год назад

    Great lesson, I need help though, my background colors do not change, the JS section does not seem to work for me

    • @billy4549
      @billy4549 Год назад +1

      It was the case for me too..but here some modifications to make:
      function changeColors(){
      var colors = ["red","blue","yellow","green","purple","orange","black"]
      var bodyElement = document.getElementsByTagName("Body")[0];
      bodyElement.style.background = colors[index++];
      if (index > colors.length -1)
      index = 0;
      }
      It should work!!

    • @bilalerdem8264
      @bilalerdem8264 Год назад +1

      @@billy4549 I f**king worship you man! thx

  • @Multaniprince557
    @Multaniprince557 Год назад

    Thanks Boss!

  • @farhadcohan3245
    @farhadcohan3245 2 года назад

    Everything is exact same but when I click to add or delete it does not work I used console it show there is problem with pencil code please help here thank you again

    • @codefoxx
      @codefoxx  2 года назад +1

      Are you referring to the Grocery list project?

    • @codefoxx
      @codefoxx  2 года назад +1

      Did you add an id to the pencil in the html file?

    • @farhadcohan3245
      @farhadcohan3245 2 года назад

      @@codefoxx yes u did I followed you word by word I have to tell you my browser is Firefox I don't know if got anything to do with I checked over and over getElements but class name are no issue class by ID pencil is problem

  • @constantine9074
    @constantine9074 Год назад +1

    great content !!

  • @teflonrozay1074
    @teflonrozay1074 Год назад

    Nice one

  • @grigoldvali4124
    @grigoldvali4124 5 месяцев назад +1

    Hello, can you explain, why this code doesnt work?
    thanks a lot
    var index = 0;
    function changeColors(){
    var colors = ["red", "blue", "green",
    "yellow", "orange", "purple"];
    document.getElementsByTagName("body"[0]).
    style.background = colors[index++];
    if(index > colors.length - 1)
    index = 0;
    }

    • @Minh-tx9qp
      @Minh-tx9qp 5 месяцев назад

      hello i am new to coding but i can maybe help :
      you wrote ("body"[0]) instead of ("body")[0].

    • @grigoldvali4124
      @grigoldvali4124 5 месяцев назад +1

      @@Minh-tx9qp thanks

  • @thisizavian3691
    @thisizavian3691 Год назад

    Great video a series! I have one input, why didn't you just do if(index > 5). It produces the same result. Thanks!

    • @dr.kamrunnahar2209
      @dr.kamrunnahar2209 Год назад +2

      Since you can use as many colors in array, this (color.length) will work every time, Doesn't matter how many colors are there in the array...

    • @thisizavian3691
      @thisizavian3691 Год назад

      @@dr.kamrunnahar2209 ahhhh, I seee. Thanks.

    • @areebahmed1773
      @areebahmed1773 Год назад

      @@dr.kamrunnahar2209 and we dont need to put -1 in color.length, right?

    • @HHJoshHH
      @HHJoshHH Год назад

      Followed this tutorial perfectly but I can’t get the colors to start over again at red.
      Can ya help me?

  • @cristaltechaira1602
    @cristaltechaira1602 3 года назад

    Thanks

  • @msd5495
    @msd5495 3 года назад

    create project using time interval

    • @codefoxx
      @codefoxx  3 года назад +3

      Just include the setTimeout() function inside the changeColor() function and set it to whatever time you want. For example, setTimeout(changeColor, 3000)

    • @msd5495
      @msd5495 3 года назад

      @@codefoxx okay