The Entrepreneur Forum | Startups | Entrepreneurship | Starting a Business | Motivation | Success

JavaScript is a PAIN in the

Accelerate wealth. Build a business that pays freedom. Join more than 70,000 entrepreneurs and register for the Fastlane Entrepreneur forum. Remove ads? Join the INSIDERS.

David Borodin

Contributor
Read Millionaire Fastlane!
Oct 1, 2021
36
25
45
Hello Everyone,
I going to try to explain as short and simple as possible.

So, recently I was programming a javascript for my website, but something went wrong...
The javascript does not show up on the website.
I watched countless of videos of this problem, but nothing solves it.
I also tried to rewrite the code several times as well.

-------------------------------------------------------------------------
(I am using "Visual Studio Code")

1: I made a new file called (script.js)
2: I wrote this in:

var menuIcon = document.querySelector("menu-icon");
var sidebar = document.querySelector(".sidebar");
menuIcon.onclick = function(){
const newLocal = "small-sidebar";
sidebar.classList.toggle();
}
3: I then connected this file to the index.html

--------------------------------------------------------------------

But STILL it does not work.
Do you see anything wrong here?
 
Don't like ads? Remove them while supporting the forum: Subscribe to Fastlane Insiders.

Black_Dragon43

Gold Contributor
Read Millionaire Fastlane!
Speedway Pass
Apr 28, 2017
791
2,236
553
Eastern Europe
Hello Everyone,
I going to try to explain as short and simple as possible.

So, recently I was programming a javascript for my website, but something went wrong...
The javascript does not show up on the website.
I watched countless of videos of this problem, but nothing solves it.
I also tried to rewrite the code several times as well.

-------------------------------------------------------------------------
(I am using "Visual Studio Code")

1: I made a new file called (script.js)
2: I wrote this in:

var menuIcon = document.querySelector("menu-icon");
var sidebar = document.querySelector(".sidebar");
menuIcon.onclick = function(){
const newLocal = "small-sidebar";
sidebar.classList.toggle();
}
3: I then connected this file to the index.html

--------------------------------------------------------------------

But STILL it does not work.
Do you see anything wrong here?
Bro! Put a f*cking dot before "menu-icon". Should be var menuIcon = document.querySelector(".menu-icon"); if you're selecting a class.

Also specify in brackets what class you want to add/remove in .toggle("YOUR CLASS GOES HERE")
 

Martin Z

Bronze Contributor
Read Rat-Race Escape!
Read Millionaire Fastlane!
Read Unscripted!
Speedway Pass
Oct 11, 2021
202
126
73
Stavanger, Norway
Hello Everyone,
I going to try to explain as short and simple as possible.

So, recently I was programming a javascript for my website, but something went wrong...
The javascript does not show up on the website.
I watched countless of videos of this problem, but nothing solves it.
I also tried to rewrite the code several times as well.

-------------------------------------------------------------------------
(I am using "Visual Studio Code")

1: I made a new file called (script.js)
2: I wrote this in:

var menuIcon = document.querySelector("menu-icon");
var sidebar = document.querySelector(".sidebar");
menuIcon.onclick = function(){
const newLocal = "small-sidebar";
sidebar.classList.toggle();
}
3: I then connected this file to the index.html

--------------------------------------------------------------------

But STILL it does not work.
Do you see anything wrong here?
You forgot the . in your querySelector for menu-icon.
 

Toyotomi

Contributor
Jun 27, 2021
16
25
14
27
United Kingdom
Hello Everyone,
I going to try to explain as short and simple as possible.

So, recently I was programming a javascript for my website, but something went wrong...
The javascript does not show up on the website.
I watched countless of videos of this problem, but nothing solves it.
I also tried to rewrite the code several times as well.

-------------------------------------------------------------------------
(I am using "Visual Studio Code")

1: I made a new file called (script.js)
2: I wrote this in:

var menuIcon = document.querySelector("menu-icon");
var sidebar = document.querySelector(".sidebar");
menuIcon.onclick = function(){
const newLocal = "small-sidebar";
sidebar.classList.toggle();
}
3: I then connected this file to the index.html

--------------------------------------------------------------------

But STILL it does not work.
Do you see anything wrong here?
@Black_Dragon43 and @Martin Z are both right on the cash, beyond that, are you deploying this anywhere? Or are you doing all of this locally?

Can we see how you are adding the script? Do please include your index.html as well.

Also as a tip don't expect things to just exist check if sidebar exist (useful in the future when stuff changes moves around), also prefer to pass sidebar as an argument instead of having it as a global variable at the top of your script.

Here is a code pen I made for just you friend. Hopefully it helps.
 
Last edited:

Mainstream7

Beauty is Truth
Speedway Pass
Jan 1, 2015
523
640
296
31
Hey man, The Fastlane Forum isn't a coding forum. I suggest you look into coding Discords or sites like StackOverflow for code support.

You will also find a good Javascript curriculum(including Discord) on theodinproject.com
 

Sponsored Offers

  • Sticky
MARKETPLACE  You Are One Call Away From Living Your Dream Life - LightHouse’s Accountability Program ⚡
What I got was completely unexpected; @LightHouse generously talked with me for 2 straight hours...
  • Sticky
MARKETPLACE  Freelance University: Solve Every Freelance Problem (Especially on Upwork)
FU. 4 DAYS. 50% OFF BLACK FRIDAY SALE! If you're an Upwork freelancer, you'd be a fool not to...
  • Sticky
MARKETPLACE  For Sale: Food Brand with 4 Years of Happy Customers in a Fast-Growing Niche
So to get certified, it cost a fortune? How much exactly? That sucks that these "health...
MARKETPLACE  Fox Web School "Legend" Group Coaching Program 2021
Fox's Web School helps you learn a specialized skill which you can use to get to Fastlane. It's...
MARKETPLACE  Not sure how to start? This free book will teach you how to build a successful web design business
Hi Fox. Starting the book and got through the introduction. Had a conversation with Andy Black...


Don't like ads? Remove them while supporting the forum. Subscribe.

Fastlane Insiders

View the forum AD FREE.
Private, unindexed content
Detailed process/execution threads
Ideas needing execution, more!

Join Fastlane Insiders.

Top Bottom