Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialolu adesina
23,007 Pointscan i use a or operator || in c#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace interactive_quiz
{
class Program
{
static void Main(string[] args)
{
var score = 0;
Console.Write("liverpool have won 5 european cups ");
var answer1 = Console.ReadLine();
if (answer1.ToLower() == "true")
{
score += 1;
}
else if (answer1.ToLower()!= "true"||"false")// this line of code is giving me an error why
{
Console.WriteLine("please answer true or false");
};
Console.Write("liverpool won the premier League in 1999 ");
var answer2 = Console.ReadLine();
if (answer2.ToLower() == "false")
{
score += 1;
}
Console.Write("liverpool's home ground is at anfield ");
var answer3 = Console.ReadLine();
if (answer3.ToLower() == "true")
{
score += 1;
}
Console.WriteLine("your score is " + score);
Console.ReadLine();
}
}
}
2 Answers
Jason Anders
Treehouse Moderator 145,860 PointsHey Olu,
If I remember the syntax correctly, you have to repeat the conditional statement on both sides of the || operator. So, give this a try:
else if (answer1.ToLower() != "true") || (answer1.ToLower() != "false")
olu adesina
23,007 Pointsi managed to get it in the end the syntax is actually
else if ((answer1.ToLower() != "true") || (answer1.ToLower() != "false"))