2D game turning

How can I make my character turn around to left and right when I press “a” and “d”

if (Input.GetKeyDown(“d”)){
if(transform.rotation != Quaternion.Euler(0, 180, 0))
transform.rotation = Quaternion.Euler(0, 180, 0);
}

		if (Input.GetKeyDown("a")){
			if(transform.rotation != Quaternion.Euler(0, 0, 0))
				transform.rotation = Quaternion.Euler(0, 0, 0);
		}

Try using that. That is the code I used for my game. Also, before posting on here, make sure you have Googled this subject first. If it is not on Google (Most likely not) then post your question right here.