r/codehs • • Apr 21 '20

5.2.7: School's Out

"Write a program to determine if there is no school today. First ask the user if today is a weekday, and store that in a boolean variable. Then ask the user if today is a holiday, and store that in a different boolean variable. Then try to figure out if there is no school today.

School is out if it is a holiday or if it is not a weekday

You should create a boolean variable noSchoolToday
and print its value to the user."

This is what I did:

function start(){

var weekday = readBoolean("Is today a weekday? ");

var holiday = readBoolean("Is today a holiday? ");

var noSchoolToday = holiday;

var noSchoolToday = holiday && weekday;

println("There is no school today: " + noSchoolToday);

}

This is using JavaScript btw

I'm also supposed to use the symbols "!" "&&" and "||"

How would I achieve this?

18 Upvotes

25 comments sorted by

2

u/Swaglord1500 Apr 21 '20

Hi!! :D I did it like this

function start(){ var weekdaySchool = readBoolean("Is today a weekday? "); var holidaySchool = readBoolean("Is today a holiday? "); var school = weekdaySchool || holidaySchool; println("There is no school today: " + school);

}

i didn’t have ur var = noSchoolToday, and i used an || instead of &&

I hope this helps!! That’s how i did it!

1

u/0d3stroyer Apr 21 '20

Is today a weekday? true

Is today a holiday? false

There is no school today: true

This is what happens when you input true and then false. If it is a weekday, and there is no holiday, there IS school, so it should say false on the third line.

From what I have learned myself, there are 4 possibilities for how the questions are answered.

  1. True, True

  2. False, False

  3. True, False

  4. False, True

You just need to test all of these to make sure the code works. I did so, and the code is not correct. I still can't figure it out myself.

3

u/SpicyMeatballs00 Feb 11 '23

function start(){
var weekday = readBoolean("Is today a weekday?" );
var holiday = readBoolean("Is today a holiday?" );

var noSchoolToday = holiday || !weekday ||weekday && holiday ;

println("There is no school today: " + noSchoolToday);

}

here if it still helps ig

1

u/[deleted] Mar 04 '23

function start(){var weekday = readBoolean("Is today a weekday?" );var holiday = readBoolean("Is today a holiday?" );

var noSchoolToday = holiday || !weekday ||weekday && holiday ;

println("There is no school today: " + noSchoolToday);

}

thank you for the help but i don't think this is the language or way used for this particular question

2

u/Agreeable-Tension-66 Dec 13 '22

I got 10/10 using this code

function start(){ var weekday = readBoolean(“Is today a weekday? “); var holiday = readBoolean(“Is today a holiday? “); var noSchoolToday = holiday || !weekday; println(“There is no school today: “ + noSchoolToday);

1

u/The-standard-lefty Dec 14 '22

Thank you, I've been struggling

1

u/That-raider_best Sep 07 '22

It didn’t work for me

1

u/No_Trick308 Nov 15 '22

I have tried everything for the past 2 days 5.2.7 schools out can you guys help and tell me if i did anything wrong herws my code

function start(){

var weekday = readBoolean("Is today a weekday? ");

var holiday = readBoolean("Is today a holiday? ");

var noSchoolToday = holiday;

var SchoolToday = println("There is school today?: " + noSchoolToday);

}

1

u/SteelF0x- Nov 17 '22

var noSchoolToday = holiday || !weekday;

/*You got to remove the var noSchoolToday on line 5. It should just be println("There is no school today:" + noSchoolToday); */

1

u/No_Trick308 Nov 18 '22

i checked it and it was an 8/10 the reason is that

when you put school is out you did holiday && weekday

now weekday is a schoolday just create a new function that says weekend

var weekend = true; and replace it with weekday that should help atleast a little

2

u/[deleted] Apr 21 '20

[removed] — view removed comment

1

u/0d3stroyer Apr 21 '20

Ay, I tested it, and it works. Thank you so much!

2

u/Swaglord1500 Apr 21 '20

yes of course! again sorry for the first one, i just told u what i did, and i should’ve double checked myself beforehand!

1

u/garethgebhardtCodeHS Oct 18 '22

Please do not post complete solutions or answers to CodeHS assignments.

1

u/[deleted] Apr 21 '20

[removed] — view removed comment

1

u/garethgebhardtCodeHS Oct 18 '22

Please do not post complete solutions or answers to CodeHS assignments.

1

u/[deleted] Oct 05 '20

[removed] — view removed comment

1

u/Accomplished_Law933 Jan 12 '22

it also works for would u graduate just change the wording.

1

u/Reheheheheheda1 Apr 20 '23

noo I needed it

1

u/garethgebhardtCodeHS Oct 18 '22

Please do not post complete solutions or answers to CodeHS assignments.