Q:

If statement / String comparison

I am new to elisp and am trying to write a simple program using an if statement. 
The point is to read in a year of school and return either 1, 2, 3, 4, or 0 for the strings "freshman", "sophomore", "junior", "senior" respectively (defaulting to 0 when no match is made.  My code is as follows:
(defun yearCode(name)
    (if ( = name "freshman") 1
      (if ( = name "sophomore") 2
        (if ( = name "junior") 3
          (if ( = name "senior") 4
            (0))))))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; main function                        ;;;
;;; input: year                          ;;;
;;; output: code corresponding to year   ;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun main (year)
 (interactive "sEnter your academic year: ")  ; read year
 (message "%d" (yearCode year)))              ; display its code

  ;;; Tests...
 (main "junior")
 (yearCode "junior")

I honestly know nothing about elisp so I am having trouble even having the first part compile. Can anyone help me construct an if statement correctly?
EDIT: I was testing in the wrong buffer -_- code worked using if statements.

A:

When you have if..elseif..elseif..else in ruby, you use cond in emacs lisp:
(defun yearCode (name)
  (cond
   ((string= name "freshman") 1)
   ((string= name "sophomore") 2)
   ((string= name "junior") 3)
   ((string= name "senior") 4)))   

That's not how I would write it, however.
(defun yearCode (name)
  (cdr (assoc name
              '(("freshman" . 1)
                ("sophomore" . 2)
                ("junior" . 3)
                ("senior" . 4)))))

There are many kind of equality, and = is strictly for numbers (or markers). string= is for strings and string designators, eq is for object identity, equal is a kind of deep equality of elements (that's why it works for strings, but it would just return false for string vs. non-string comparison, never detecting an error). This latter one, equal, is used by assoc.

A:

This would be the way to write it using if statements. An if-statement has a condition part, which is either true or false. If it is true, it evaluates the FIRST part. It can only be one sentence really, unless you use (progn ). The rest of it will be the else part of the if statement.
(defun yearCode(name)
    (if (string= name "freshman")    ; true or false?
       1                            ; if true, returns 1 

  ; Note that you can't really write anything else here. 
  ; From here on, it is the first else part!

     (if (string= name "sophomore")  ; if false, else part  etc.
       2
      (if (string= name "junior") 
        3
       (if (string= name "senior") 
         4)))))

Though this answers your question specifically about if,  I would certainly advise to use  cond  instead , like the others suggested.
Below the application of progn, in the case of TRUE, to have more than 1 expression to be evaluated.
(defun yearCode(name)
    (if (string= name "freshman")    ; true or false?
       (progn 1                      ; if true, returns 1 
              (message "this is possible!"))          

     (if (string= name "sophomore")  ; if false, else part  etc.
       2
      (if (string= name "junior") 
        3
       (if (string= name "senior") 
         4)))))

