Website (Day checker)

  • (2 Pages)
  • +
  • 1
  • 2

25 Replies - 786 Views - Last Post: 02 May 2019 - 01:15 AM

#1 panda00   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 01-May 19

Website (Day checker)

Posted 01 May 2019 - 03:10 AM

Hi, it has been many years since i have done any coding at uni, trying to make something for work where it checks the day and time and then displays text depending on that on the webpage. i could be no where near the right thing i have no idea

<strong class="GeneratedText">
    <script type="text/javascript">
        document.write("<p>");
        var day = new Date();
        var weekday = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
        var d = weekday[day.getDay()];
        var hr = day.getHours();
        if      ( d == "Monday" || d == "Tuesday" || d == "Wednesday" || d == "Thursday")) {
            document.write("Order By 1pm, We Can Deliver Tomorrow!");
       }    else if (((hr == 13) || (hr == 23)) &&
            ( d == "Thursday")) {
            document.write(" Order By 1pm Friday, We Can Deliver Monday!");
        }      else if (((hr == 00) || (hr == 12)) &&
            ( d == "Friday")) {
            document.write(" Order By 1pm Friday, We Can Deliver Monday!");
       }      else if (((hr == 13) || (hr == 23)) &&
            ( d == "Friday")) {
            document.write(" Order By 1pm Monday, We Can Deliver Tuesday!"); }
              else if ( d == "Saturday" || d == "Sunday")) {
            document.write("Order By 1pm Monday, We Can Deliver Tuesday!"); }
 
 
        document.write("</p>");
    </script>
</strong>



Is This A Good Question/Topic? 0
  • +

Replies To: Website (Day checker)

#2 andrewsw   User is online

  • quantum multiprover
  • member icon

Reputation: 6792
  • View blog
  • Posts: 28,046
  • Joined: 12-December 12

Re: Website (Day checker)

Posted 01 May 2019 - 03:23 AM

What happens when you run your code?
Are there errors in your browser's console? Open the browser's developer tools.
Was This Post Helpful? 0
  • +
  • -

#3 panda00   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 01-May 19

Re: Website (Day checker)

Posted 01 May 2019 - 03:31 AM

Hi,

When put into the websites code it doesn't bring up any errors and just displays nothing on the page.
Was This Post Helpful? 0
  • +
  • -

#4 g00se   User is online

  • D.I.C Lover
  • member icon

Reputation: 3623
  • View blog
  • Posts: 16,656
  • Joined: 20-September 08

Re: Website (Day checker)

Posted 01 May 2019 - 03:35 AM

Posting Javascript questions in the Java TA is not appropriate, and might make your question less likely to be answered. http://technojeeves....ipt-is-not-java

Moving
Was This Post Helpful? 0
  • +
  • -

#5 andrewsw   User is online

  • quantum multiprover
  • member icon

Reputation: 6792
  • View blog
  • Posts: 28,046
  • Joined: 12-December 12

Re: Website (Day checker)

Posted 01 May 2019 - 03:41 AM

It does produce an error for me. Did you look in the browser's developer tools?
Was This Post Helpful? 0
  • +
  • -

#6 panda00   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 01-May 19

Re: Website (Day checker)

Posted 01 May 2019 - 03:47 AM

View Postandrewsw, on 01 May 2019 - 03:41 AM, said:

It does produce an error for me. Did you look in the browser's developer tools?


Im guessing not in the right place, been long time since i done any code so getting my self confused, just trying to get this to work as currently someone manually changes a bit of text 3 times a week on our webpae when i know something along these lines can do the job, im just lot more rust then i thought as i honestly dont know whats wrong with it
Was This Post Helpful? 0
  • +
  • -

#7 andrewsw   User is online

  • quantum multiprover
  • member icon

Reputation: 6792
  • View blog
  • Posts: 28,046
  • Joined: 12-December 12

Re: Website (Day checker)

Posted 01 May 2019 - 03:50 AM

You could search "(your browser name) developer tools" to discover how to find them. Typically, press F12 or right-click, Inspect.
Was This Post Helpful? 0
  • +
  • -

#8 panda00   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 01-May 19

Re: Website (Day checker)

Posted 01 May 2019 - 04:20 AM

View Postandrewsw, on 01 May 2019 - 03:50 AM, said:

You could search "(your browser name) developer tools" to discover how to find them. Typically, press F12 or right-click, Inspect.



ok so the error i am seeing is SyntaxError: expected expression, got '&&' but i am unsure what to doto fix this tried messing bout but cant get rid of it
Was This Post Helpful? 0
  • +
  • -

#9 andrewsw   User is online

  • quantum multiprover
  • member icon

Reputation: 6792
  • View blog
  • Posts: 28,046
  • Joined: 12-December 12

Re: Website (Day checker)

Posted 01 May 2019 - 04:36 AM

I got a different error from your code, "test1.html:14 Uncaught SyntaxError: Unexpected token )" which is because you have a redundant closing parentheses at that line (and further down).

If you have revised the code then post your latest version and quote the error details exactly.

Was This Post Helpful? 0
  • +
  • -

#10 panda00   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 01-May 19

Re: Website (Day checker)

Posted 01 May 2019 - 04:42 AM

View Postandrewsw, on 01 May 2019 - 04:36 AM, said:

I got a different error from your code, "test1.html:14 Uncaught SyntaxError: Unexpected token )" which is because you have a redundant closing parentheses at that line (and further down).

If you have revised the code then post your latest version and quote the error details exactly.



I removed a few brackets as had extra on most lines and im now getting the error message (SyntaxError: expected expression, got '&&' )

 <strong class="GeneratedText">
    <script type="text/javascript">
        document.write("<p>");
        var day = new Date();
        var weekday = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
        var d = weekday[day.getDay()];
        var hr = day.getHours();
        if      (( d == "Monday" || d == "Tuesday" || d == "Wednesday" || d == "Thursday")) {
            document.write("Order By 1pm, We Can Deliver Tomorrow!");
       }    else if (( d == "Thursday")) && ((hr == 13) || (hr == 23)) {
            document.write(" Order By 1pm Friday, We Can Deliver Monday!");
        }      else if (( d == "Friday")) && ((hr == 00) || (hr == 12) {
            document.write(" Order By 1pm Friday, We Can Deliver Monday!");
       }      else if (( d == "Friday")) && ((hr == 13) || (hr == 23)) {
            document.write(" Order By 1pm Monday, We Can Deliver Tuesday!"); }
              else if (( d == "Saturday" || d == "Sunday")) {
            document.write("Order By 1pm Monday, We Can Deliver Tuesday!"); }


        document.write("</p>");
    </script>
</strong>


Was This Post Helpful? 0
  • +
  • -

#11 andrewsw   User is online

  • quantum multiprover
  • member icon

Reputation: 6792
  • View blog
  • Posts: 28,046
  • Joined: 12-December 12

Re: Website (Day checker)

Posted 01 May 2019 - 05:19 AM

What line does the error refer to.

I expect it is still an issue with misplaced brackets.
Was This Post Helpful? 1
  • +
  • -

#12 panda00   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 01-May 19

Re: Website (Day checker)

Posted 01 May 2019 - 05:51 AM

View Postandrewsw, on 01 May 2019 - 05:19 AM, said:

What line does the error refer to.

I expect it is still an issue with misplaced brackets.



Hi its line 10 but id expect it to happen on the lines below as well
Was This Post Helpful? 0
  • +
  • -

#13 panda00   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 01-May 19

Re: Website (Day checker)

Posted 01 May 2019 - 05:59 AM

fixed it, was missing a bracket in 1 line and too many on another

thanks for the help
Was This Post Helpful? 0
  • +
  • -

#14 panda00   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 01-May 19

Re: Website (Day checker)

Posted 01 May 2019 - 07:13 AM

I have made changes for more IF statements and removed the top one it is now not displaying anything and showing no errors on the debug console (im not sure before if it was only checking the top statement and then skipping the rest so its not liking the hours maybe?

<strong class="GeneratedText">
    <script type="text/javascript">
        document.write("<p>");
        var day = new Date();
        var weekday = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
        var d = weekday[day.getDay()];
        var hr = day.getHours();
        if      (( d == "Monday") && (hr == 00) || (hr == 12)) {
            document.write("Order By 1pm, We Can Deliver Tomorrow!"); }    
	else if (( d == "Monday") && (hr == 13) || (hr == 23)) {
            document.write(" Order By 1pm Tomorrow, We Can Deliver Wednesday!"); }    	
	else if (( d == "Tuesday") && (hr == 00) || (hr == 12)) {
            document.write("Order By 1pm, We Can Deliver Tomorrow!"); }    
	else if (( d == "Tuesday") && (hr == 13) || (hr == 23)) {
            document.write(" Order By 1pm Tomorrow, We Can Deliver Thursday!"); }    
	else if (( d == "Wednesday") && (hr == 00) || (hr == 12)) {
            document.write("Order By 1pm, We Can Deliver Tomorrow!"); }    
	else if (( d == "Wednesday") && (hr == 13) || (hr == 23)) {
            document.write(" Order By 1pm Tomorrow, We Can Deliver Friday!"); }    
	else if (( d == "Thursday") && (hr == 00) || (hr == 12)) {
            document.write(" Order By 1pm, We Can Deliver Tomorrow!");}    
	else if (( d == "Thursday") && (hr == 13) || (hr == 23)) {
            document.write(" Order By 1pm Friday, We Can Deliver Monday!"); }      
	else if (( d == "Friday") && (hr == 00) || (hr == 12)) {
            document.write(" Order By 1pm, We Can Deliver Monday!"); }      
	else if (( d == "Friday") && (hr == 13) || (hr == 23)) {
            document.write(" Order By 1pm Monday, We Can Deliver Tuesday!"); }
        else if (( d == "Saturday" || d == "Sunday")) {
            document.write("Order By 1pm Monday, We Can Deliver Tuesday!"); }


        document.write("</p>");
    </script>
</strong>


Was This Post Helpful? 0
  • +
  • -

#15 andrewsw   User is online

  • quantum multiprover
  • member icon

Reputation: 6792
  • View blog
  • Posts: 28,046
  • Joined: 12-December 12

Re: Website (Day checker)

Posted 01 May 2019 - 07:30 AM

By adjusting the parens you have changed the logic of statements like this

else if (( d == "Monday") && (hr == 13) || (hr == 23)) {


&& and || do not have the same precedence.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2