Help with code- user.Agent

Help with code- user.Agent
0.0 0

#1

I am working on a JS assignment for school. Our instructions are to use user.Agent to detect the browser that the user is browsing with. The web page background color and text color must appear differently depending on the browser being used.

The instructions we were given were pretty vague. I am trying to format my code similar to the professor’s but something is not right.

Any help is appreciated.

Thanks


#2

Can you share a codepen link or something similar so we can see what you’ve got so far and where you might be stuck?

The task doesn’t sound that vague - but maybe I’m missing something?


#3

Yes. I am pretty new to Codepen. It is interesting splitting up each section but that is basically it. I am going off of a powerpoint with some example code. I say vague because I understand my goal but we were not completely taught how to accomplish the goal. I got spoiled on FCC with detailed videos, explanations and tutorials. I am not sure if it’s my syntax, if something is missing or what.

Thanks. Link: http://codepen.io/LMWBXR/pen/VKAbrE


#4

Currently you test for this (ff) && !(ch)&& !(sa) three times in your if statements, rather than mixing it up.

I’m not an expert with DOM stuff, but I think document.write overwrites the whole page as well, so maybe you need a different method to manipulate the CSS. I know there are jquery ways to manipulate the CSS style, but if you have to use JS, it’s probably pretty Googleable.

I couldn’t figure out what you were using the pos variable for? Is that another requirement of the task?


#5

Also, I noticed my own userAgent string is kinda horrible to parse, so you might like this list of possible useragent strings to figure out what the best regex matches will be: https://techblog.willshouse.com/2012/01/03/most-common-user-agents/

I looked this up when I saw that my UA is “Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36

Which to my untrained eye looks like it could be Firefox (because of the Mozilla bit), Safari (because os the appleWebKit and Safari bits), or Chome (because of the Chrome bit)…for what it’s worth, it’s Chrome, but that seems like a harder thing to parse easily.